Function assertEquals

  • Asserts equality between a value and its type.

    Asserts a parametric value type and throws a TypeGuardError with detailed reason, if the parametric value is not following the type T or some superfluous property that is not listed on the type T has been found. Otherwise, the value is following the type T without any superfluous property, 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 equals function instead. Otherwise, you want to know all the errors, validateEquals is the way to go.

    On the other hand, if you want to allow superfluous property that is not enrolled to the type T, you can use assert 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 equality between a value and its type.

    Asserts a parametric value type and throws a TypeGuardError with detailed reason, if the parametric value is not following the type T or some superfluous property that is not listed on the type T has been found. Otherwise, the value is following the type T without any superfluous property, 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 equals function instead. Otherwise, you want to know all the errors, validateEquals is the way to go.

    On the other hand, if you want to allow superfluous property that is not enrolled to the type T, you can use assert 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