GuobaGuoba Utils

notNullish

@guoba-ai/utils / guard / notNullish

Function: notNullish()

function notNullish<T>(val): val is NonNullable<T>;

Defined in: guard.ts:182

Check if a value is not null or undefined (type narrowing).

Type Parameters

T

T

Parameters

val

T | null | undefined

The value to check

Returns

val is NonNullable<T>

true if the value is not null or undefined

Example

const values = [1, null, 2, undefined, 3]
const filtered = values.filter(notNullish) // [1, 2, 3] typed as number[]

On this page