Skip to content

isDefined

isDefined<T>(value): value is T

Defined in: filtration/is-defined.ts:22

Type guard to check if a value is defined (not null or undefined). Returns a boolean indicating whether the value is defined with β€œis” for type narrowing.

Type Parameters

T

T

Describes the type of the value if the value is defined

Parameters

value

The value to check

T | null | undefined

Returns

value is T

True if the value is defined (not null or undefined); otherwise, false

Example

// Return true
isDefined(5); // true
isDefined("hello"); // true
// Return false
isDefined(null); // false
isDefined(undefined); // false