Function validateEqualsFunction

  • Validates a function with strict equality.

    Validates a function with strict equality, by wrapping the function and checking its parameters and return value through validateEquals function. If some parameter or return value does not match the expected type, it returns IValidation.IError typed object. Otherwise there's no type error, it returns IValidation.ISuccess typed object instead.

    For reference, IValidation.IError.path would be a little bit different with individual validateEquals function. If the IValidation.IError 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 finding every type errors, but just finding the 1st type error, then use assertEqualsFunction instead. Otherwise, what you want is just validating parameters or return value only, you can use validateEqualsParameters or validateEqualsReturn instead.

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

    Type Parameters

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

      Target function type

    Parameters

    • func: T

      Target function to validate

    Returns T extends ((...args: infer Arguments) => infer Output)
        ? Output extends Promise<infer R>
            ? ((...args: Arguments) => Promise<IValidation<R>>)
            : ((...args: Arguments) => IValidation<Output>)
        : never

    The wrapper function with type validations

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