Function: filterNullAndUndefinedAndEmpty()
filterNullAndUndefinedAndEmpty<
TValue
>(value
:""
|Nullish
|TValue
):value is TValue
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
Parameter | Type | Description |
---|---|---|
value | "" | Nullish | TValue | The 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']