Function isNullish

  • Checks if a value is null or undefined.

    Parameters

    • value: unknown

      The value to check.

    Returns value is undefined | null

    true if the check passes, false otherwise.

    Example

    Basic usage

    isNullish(null) // true
    isNullish(undefined) // true
    isNullish(0) // false

    Type narrowing

    const value: string | null | undefined

    if (isNullish(value)) {
    value // type: null | undefined
    } else {
    value // type: string
    }

    // or
    if (!isNullish(value)) {
    value // type: string
    } else {
    value // type: null | undefined
    }

    Paired with assert

    import { assert } from 'uft'

    const token: string | null | undefined
    assert(!isNullish(token), 'received nullish token')
    token // string

Generated using TypeDoc