Created
May 20, 2023 20:39
-
-
Save dan-lee/a9199950d88a2016ed06e81678adcb02 to your computer and use it in GitHub Desktop.
Throwing date
This file contains 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
export class ThrowingDate extends Date { | |
constructor(...args: ConstructorParameters<typeof Date>) { | |
super(...args) | |
const date = new Date(...args) | |
if (isNaN(+date)) { | |
throw new Error('Invalid date') | |
} | |
return date | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment