DocsCommonutilitiesNotNullOrUndefined
Package: @hexos/common

Type guard predicate that filters out null and undefined values from arrays.

Designed for use in .filter() operations where the resulting array should have a narrowed type excluding nullable elements. The type predicate ensures TypeScript correctly infers the filtered type.

Example

const items: (string | null | undefined)[] = ['a', null, 'b', undefined];
const filtered: string[] = items.filter(notNullOrUndefined);
// => ['a', 'b'] with type string[]
function notNullOrUndefined<T>(val: T | undefined | null): val is T

Parameters

val

T | undefined | null