Function assert

  • Asserts a value type.

    Asserts a parametric value type and throws a TypeGuardError with detailed reason, if the parametric value is not following the type T. Otherwise, the value is following the type T, just input parameter would be returned.

    If what you want is not asserting but just knowing whether the parametric value is following the type T or not, you can choose the is function instead. Otherwise you want to know all the errors, validate is the way to go. Also, if you want to automatically cast the parametric value to the type T when no problem (perform the assertion guard of type).

    On the other and, if you don't want to allow any superfluous property that is not enrolled to the type T, you can use assertEquals function instead.

    Type Parameters

    • T

      Type of the input value

    Parameters

    • input: T

      A value to be asserted

    • OptionalerrorFactory: ((props: TypeGuardError.IProps) => Error)

      Custom error factory. Default is TypeGuardError

    Returns T

    Parametric input value

    A TypeGuardError instance with detailed reason

    Jeongho Nam - https://github.com/samchon

  • Asserts a value type.

    Asserts a parametric value type and throws a TypeGuardError with detailed reason, if the parametric value is not following the type T. Otherwise, the value is following the type T, just input parameter would be returned.

    If what you want is not asserting but just knowing whether the parametric value is following the type T or not, you can choose the is function instead. Otherwise, you want to know all the errors, validate is the way to go.

    On the other and, if you don't want to allow any superfluous property that is not enrolled to the type T, you can use assertEquals function instead.

    Type Parameters

    • T

      Type of the input value

    Parameters

    • input: unknown

      A value to be asserted

    • OptionalerrorFactory: ((props: TypeGuardError.IProps) => Error)

      Custom error factory. Default is TypeGuardError

    Returns T

    Parametric input value casted as T

    A TypeGuardError instance with detailed reason

    Jeongho Nam - https://github.com/samchon