ts-data-forge
    Preparing search index...

    Function isNonNullish

    • Type guard that checks if a value is not null or undefined (non-nullish).

      This function uses the loose inequality operator (!=) to check that a value is neither null nor undefined in a single comparison. This is equivalent to TypeScript's NonNullable<T> utility type.

      Type Narrowing Behavior:

      • Excludes both null and undefined from the input type when true
      • Equivalent to applying TypeScript's NonNullable<T> utility type
      • Commonly used to filter out nullish values from arrays

      Type Parameters

      • T

        The type of the input value

      Parameters

      • u: T

        The value to check

      Returns u is NonNullable<T>

      true if u is not null and not undefined, false otherwise. When true, TypeScript narrows the type to NonNullable<T>.

      const values: (string | null | undefined)[] = ['Ada', null, undefined];

      const definedValues = values.filter(isNonNullish);

      assert.deepStrictEqual(definedValues, ['Ada']);