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