Skip to content

Instantly share code, notes, and snippets.

@IntegerMan
Created November 7, 2019 04:18
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 IntegerMan/68bdee86453e7e990d12a4339d2a32f7 to your computer and use it in GitHub Desktop.
Save IntegerMan/68bdee86453e7e990d12a4339d2a32f7 to your computer and use it in GitHub Desktop.
function assertIsNumber(input: any): asserts input is number {
if (typeof(input) !== 'number') {
throw new Error('Oh snap!')
}
}
function getStandardFixedNumberString(input: string | number): string {
assertIsNumber(input); // Remove this line and we won't compile
return input.toFixed(2).toString();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment