Function ensureInstance

  • Narrows an unknown value to instance of constructor type T if it is type-compatible, or raises an error otherwise.

    Type Parameters

    Parameters

    • value: unknown

      The value to test.

    • ctor: C
    • Optionalmessage: string

      The error message to use if value is not type-compatible.

    Returns InstanceType<C>

    UnexpectedValueTypeError If the value was undefined.