Function assertEqualsFunction

  • Asserts a function with strict equality.

    Asserts a function with strict equality, by wrapping the function and checking its parameters and return value through assertEquals function. If some parameter or return value does not match the expected type, it throws an TypeGuardError or a custom error generated by the errorFactory parameter.

    For reference, TypeGuardError.path would be a little bit different with individual assertEquals function. If the TypeGuardError occurs from some parameter, the path would start from $input.parameters[number]. Otherwise the path would start from $input.return.

    • $input.parameters[0].~
    • $input.return.~

    By the way, if what you want is not just finding the 1st type error through assertion, but also finding every type errors, then use validateEqualsFunction instead. Otherwise, what you want is just asserting parameters or return value only, you can use assertEqualsParameters or assertEqualsReturn instead.

    On the other hand, if you want to allow any superfluous properties, utilize assertFunction or validateFunction instead.

    Type Parameters

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

      Target function type

    Parameters

    • func: T

      Target function to assert

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

      Custom error factory. Default is TypeGuardError

    Returns T

    The wrapper function with type assertions

    A TypeGuardError or a custom error generated by errorFactory

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