Function isObjectOrFunction

  • Type Parameters

    • T extends object

    Parameters

    • value: T

    Returns value is T

  • Determines whether a value is a non-null object or function.

    This predicate accepts all JavaScript reference values, including arrays, functions, class constructors, ordinary objects, and specialized built-in objects such as Date, Map, and Set. It rejects null and all primitive values.

    Unlike isObject, this function accepts arrays and functions.

    Known object and function types retain their existing static type. Values typed as unknown are narrowed to object.

    Parameters

    • value: unknown

      The value to evaluate.

    Returns value is object

    Whether the value is a non-null object or function.

    function execute(value: object | (() => void) | undefined): void
    {
    if (!isObjectOrFunction(value)) { return; }

    // `value` retains its object-compatible union members.
    }