Function isFunction

  • Checks if a value is typeof function.

    Parameters

    • value: unknown

      The value to check.

    Returns value is Function

    true if the check passes, false otherwise.

    Example

    Basic usage

    isFunction(() => {}) // true
    isFunction(function() {}) // true
    isFunction(async function() {}) // true
    isFunction({}) // false

    Type narrowing

    const value: { foo: string } | (() => string)

    if (isFunction(value)) {
    value // type: (() => string)
    value() // ok
    value.foo // error
    } else {
    value // type: { foo: string }
    value.foo // ok
    value() // error
    }

    // or
    if (!isFunction(value)) {
    value // type: { foo: string }
    } else {
    value // type: (() => string)
    }

Generated using TypeDoc