Skip to content

Instantly share code, notes, and snippets.

@rcdexta
Last active December 22, 2019 20:36
Show Gist options
  • Select an option

  • Save rcdexta/217d0ddc73327cbe6d9389cc15e1221e to your computer and use it in GitHub Desktop.

Select an option

Save rcdexta/217d0ddc73327cbe6d9389cc15e1221e to your computer and use it in GitHub Desktop.
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