Function assertIsNumber

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
};
  • Parameters

    • x: unknown

      The value to be asserted.

    Returns asserts x is number