Function assertGuardEquals

  • Assertion guard of a type with equality.

    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, nothing would be returned, but the input value would be automatically casted to the type T. This is the concept of "Assertion Guard" of a value type.

    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. Also, if you want to returns the parametric value when no problem, you can use assert function instead.

    On the other hand, if you want to allow 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 asserts input is T

    Parametric input value casted as T

    A TypeGuardError instance with detailed reason

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

  • Assertion guard of a type with equality.

    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, nothing would be returned, but the input value would be automatically casted to the type T. This is the concept of "Assertion Guard" of a value type.

    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. Also, if you want to returns the parametric value when no problem, you can use assertEquals function instead.

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

    Parametric input value casted as T

    A TypeGuardError instance with detailed reason

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