Asserts that the given value is a number.
An error with message 'Expected a number' if the value is not a number.
const fn = (x: unknown) => { assertIsNumber(x); // throws an error if x is not a number return x; // x has inferred type number}; Copy
const fn = (x: unknown) => { assertIsNumber(x); // throws an error if x is not a number return x; // x has inferred type number};
The value to be asserted.
Asserts that the given value is a number.
Throws
An error with message 'Expected a number' if the value is not a number.
Example