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.
filter()
const arr: (string | undefined)[] = [];const truthyArr1: string[] = arr.filter(Boolean); // TS errorconst truthyArr2: string[] = arr.filter(truthy); // no TS error Copy
const arr: (string | undefined)[] = [];const truthyArr1: string[] = arr.filter(Boolean); // TS errorconst truthyArr2: string[] = arr.filter(truthy); // no TS error
The value to test.
true if the value is truthy.
true
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.