Skip to content

assertcheck v1.0.0


assertcheck / assert / notNil

Function: notNil()

ts
function notNil<T>(v, opts?): asserts v is NonNullable<T>;

Defined in: src/assert.ts:102

Asserts that a value is not null or undefined. Narrows the type to NonNullable<T> after the call.

Type Parameters

Type Parameter
T

Parameters

ParameterTypeDescription
vT | null | undefinedThe value to check.
opts?OptsOptional message / context.

Returns

asserts v is NonNullable<T>

Example

ts
assert.notNil(user, "user must exist")
user.name // TypeScript now knows user is not null/undefined

Released under the Apache 2.0 License. Built by Vagabond Studio — senior-only for growing companies.