isTruthy
Checks if a value is truthy (not false, null, undefined, 0, "", or NaN).
This is the type-safe alternative to Boolean() as a filter callback.
Unlike filter(Boolean), using filter(isTruthy) correctly narrows the
resulting array type by excluding falsy values.
Available since v2.0.0
Import
Section titled “Import”Signature
Section titled “Signature”Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
value | Falsy | T | The value to check |
Returns
Section titled “Returns”value is T — True if the value is truthy
Examples
Section titled “Examples”Check truthy values
Section titled “Check truthy values”Returns true for all truthy values, false for falsy ones.
Type-safe filter alternative to Boolean
Section titled “Type-safe filter alternative to Boolean”Use isTruthy with Array.filter to get correct TypeScript narrowing.
