Last active
December 22, 2019 20:36
-
-
Save rcdexta/217d0ddc73327cbe6d9389cc15e1221e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function isDate(input: unknown) { | |
| if (input instanceof Date) | |
| return; | |
| else | |
| throw new Error('Input must be a Date!'); | |
| } | |
| function getDayOfWeek(input: unknown) : number { | |
| isDate(input); | |
| return input.getFullYear() // TypeScript will fail compilation here! | |
| } | |
| console.log(getDayOfWeek(new Date('2019-01-01'))); | |
| console.log(getDayOfWeek('2019-01-01')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment