This is a type predicate - if x is neither null or undefined, then it's T.
x
null
undefined
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 nonNullableArray = array.filter(isNonNullable);
nonNullableArray will be [0, 5, false, true, "", "hello"] and will have the following type: Array<string | number | boolean>.
nonNullableArray
[0, 5, false, true, "", "hello"]
Array<string | number | boolean>
NOTE: The term "nullable" in TypeScript refers to either null or undefined. This terminology is taken from https://www.typescriptlang.org/docs/handbook/utility-types.html#nonnullabletype.
Generated using TypeDoc
This is a type predicate - if
x
is neithernull
orundefined
, 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 nonNullableArray = array.filter(isNonNullable);
nonNullableArray
will be[0, 5, false, true, "", "hello"]
and will have the following type:Array<string | number | boolean>
.NOTE: The term "nullable" in TypeScript refers to either
null
orundefined
. This terminology is taken from https://www.typescriptlang.org/docs/handbook/utility-types.html#nonnullabletype.