Skip to main content

Function: filterNullAndUndefinedAndEmpty()

filterNullAndUndefinedAndEmpty<TValue>(value: "" | Nullish | TValue): value is TValue

Defined in: filterNullAndUndefinedAndEmpty.ts:19

Checks whether a value is not null nor undefined nor '' (empty string). This can be used in Array.filter to remove null, undefined from the array type

Type Parameters​

Type Parameter
TValue

Parameters​

ParameterTypeDescription
value"" | Nullish | TValueThe value to verify that is neither null, undefined nor '' (empty string)

Returns​

value is TValue

A boolean that is true if the value is neither null, undefined nor '' (empty string), false otherwise.

Example​

// TypeScript Type: (string | undefined | null)[]
const someArray = ['one', 'two', undefined, null, ''];

// TypeScript Type: string[]
const filteredArray = someArray.filter(filterNullAndUndefinedAndEmpty);
// Result: ['one', 'two']