VDL Plugin SDK

isNotNil

Import from @varavel/vdl-plugin-sdk/utils/predicates.

function isNotNil<T>(x): x is T;

Checks if the given value is not null nor undefined.

The main use of this function is to be used with TypeScript as a type predicate.

Type Parameters

Type ParameterDescription
TThe type of value.

Parameters

ParameterTypeDescription
xT | null | undefinedThe value to test if it is not null nor undefined.

Returns

x is T

True if the value is not null nor undefined, false otherwise.

Example

// Here the type of `arr` is (number | undefined)[]
const arr = [1, undefined, 3];
// Here the type of `result` is number[]
const result = arr.filter(isNotNil);
// result will be [1, 3]