Function isOrCrash

  • Verify the given value passes the guard. If not, throw an exception.

    Type Parameters

    • T

    Parameters

    • guard: ((x) => x is T)
        • (x): x is T
        • Parameters

          • x: unknown

          Returns x is T

    • Optional message: string

    Returns ((x) => T)

      • (x): T
      • Parameters

        • x: unknown

        Returns T

    Example

    const a = isOrCrash(isNumber)(4 as unknown); // a is of type number, doesn't throw
    const b: number = a; // ok
  • Type Parameters

    • T

    Parameters

    • guard: ((x) => x is T)
        • (x): x is T
        • Parameters

          • x: unknown

          Returns x is T

    • errorFactory: (() => unknown)
        • (): unknown
        • Returns unknown

    Returns ((x) => T)

      • (x): T
      • Parameters

        • x: unknown

        Returns T

Generated using TypeDoc