@ekim088/toolkit
    Preparing search index...

    Function truthy

    • Tests if a value is truthy. Can be passed as the callback to an Array filter() method to correctly infer the type of the resulting array items.

      const arr: (string | undefined)[] = [];
      const truthyArr1: string[] = arr.filter(Boolean); // TS error
      const truthyArr2: string[] = arr.filter(truthy); // no TS error

      Type Parameters

      • TruthyValue

      Parameters

      • value: false | "" | 0 | TruthyValue | null | undefined

        The value to test.

      Returns value is TruthyValue

      true if the value is truthy.