Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.