Function assertType

  • 💥 immediate 🚦 assertion

    Assert the subject satisfies the specified type T

    Type Parameters

    • T

    Parameters

    • subject: T

    Returns asserts subject is T

  • Type Parameters

    • T

    Parameters

    • subject: unknown
    • validator: ((s: T) => boolean)
        • (s): boolean
        • Parameters

          Returns boolean

    Returns asserts subject is T

  • Type Parameters

    • T extends (new (..._args: any[]) => any)

    Parameters

    • subject: unknown
    • classConstructor: T

    Returns asserts subject is InstanceType<T>

    this is not a failsafe test

Methods

  • creates a custom assertion function with standard TypeError. Currently this requires explicity type annotation, thus making it hard to use: https://github.com/microsoft/TypeScript/issues/41047

    Type Parameters

    • T

    Parameters

    • validator: ((s: T) => boolean)
        • (s): boolean
        • Parameters

          Returns boolean

    Returns ((subject: unknown) => asserts subject is T)

      • (subject): asserts subject is T
      • Parameters

        • subject: unknown

        Returns asserts subject is T