Function isObjectLoose

  • Checks if a value is typeof object and not null.

    Type Parameters

    • T

    Parameters

    • value: T

      The value to check.

    Returns value is T extends Function
        ? never
        : T & object

    true if the check passes, false otherwise.

    Remarks

    This function will return true for an array. If you do not want this behavior, use isObject instead.

    Example

    Basic usage

    isObjectLoose({}) // true
    isObjectLoose([]) // true
    isPlainObject(null) // false

    Type narrowing

    const value: string | { foo: string }

    if (isObjectLoose(value)) {
    value // type: { foo: string }
    } else {
    value // type: string
    }

    // warning: arrays will pass
    const value: { bar: string } | string[] | null

    if (isObjectLoose(value)) {
    value // type: { bar: string } | string[]
    } else {
    value // type: null
    }

Generated using TypeDoc