This is a type predicate - if x is "truthy", then it's T.
x
T
This can be used with Array's .filter() method to remove non-truthy values from an array, e.g.
.filter()
const array = [0, 5, false, true, "", "hello", undefined, null]; const truthyArray = array.filter(isTruthy);
truthyArray will be [5, true, "hello"] and will have the following type: Array<string | number | true>.
truthyArray
[5, true, "hello"]
Array<string | number | true>
Generated using TypeDoc
This is a type predicate - if
x
is "truthy", then it'sT
.This can be used with Array's
.filter()
method to remove non-truthy values from an array, e.g.const array = [0, 5, false, true, "", "hello", undefined, null]; const truthyArray = array.filter(isTruthy);
truthyArray
will be[5, true, "hello"]
and will have the following type:Array<string | number | true>
.