Type guard that checks if a value is not null.
null
Type Narrowing Behavior:
true
undefined
The type of the input value (which could be null)
The value to check
true if u is not null, false otherwise. When true, TypeScript excludes null from the type.
u
false
const values: (number | null)[] = [null, 5];const nonNullValues = values.filter(isNotNull);assert.deepStrictEqual(nonNullValues, [5]); Copy
const values: (number | null)[] = [null, 5];const nonNullValues = values.filter(isNotNull);assert.deepStrictEqual(nonNullValues, [5]);
Type guard that checks if a value is not
null
.Type Narrowing Behavior:
null
from the input type whentrue
undefined