Function assertIsNonNullable

Asserts that a value is not null or undefined.

Error if the value is null or undefined.

const fn = (x?: number | null) => {
assertIsNonNullable(x); // throws an error if x is null or undefined
return x; // x has inferred type number
};
  • Type Parameters

    • T

    Parameters

    • x: T

      The value to be asserted.

    Returns asserts x is NonNullable<T>