Skip to content

Instantly share code, notes, and snippets.

@dan-lee
Created May 20, 2023 20:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dan-lee/a9199950d88a2016ed06e81678adcb02 to your computer and use it in GitHub Desktop.
Save dan-lee/a9199950d88a2016ed06e81678adcb02 to your computer and use it in GitHub Desktop.
Throwing date
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