Function isFunction

  • Tests a function.

    Tests a function, by wrapping the function and checking its parameters and return value through is function. If some parameter or return value does not match the expected type, it returns null. Otherwise there's no type error, it returns the result of the function.

    By the way, if you want is not just testing type checking, but also finding detailed type error reason(s), then use assertFunction or validateFunction instead.

    On the other hand, if you don't want to allow any superfluous properties, utilize equalsFunction, assertEqualsFunction or validateEqualsFunction instead.

    Type Parameters

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

      Target function type

    Parameters

    • func: T

      Target function to test

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

    The wrapper function with type tests

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