Skip to main content

Assert

Helper functions that have to do with asserting.

Functions

assertDefined()

function assertDefined<T>(value, ...__namedParameters): asserts value is Exclude<T, undefined>

Helper function to throw an error if the provided value is equal to undefined.

This is useful to have TypeScript narrow a T | undefined value to T in a concise way.

Type Parameters

Type Parameter
T

Parameters

ParameterType
valueT
...__namedParameters[undefined] extends [T] ? [string] : ["The assertion is useless because the provided value does not contain undefined."]

Returns

asserts value is Exclude<T, undefined>

Defined in

functions/assert.ts:12


assertNotNull()

function assertNotNull<T>(value, ...__namedParameters): asserts value is Exclude<T, null>

Helper function to throw an error if the provided value is equal to null.

This is useful to have TypeScript narrow a T | null value to T in a concise way.

Type Parameters

Type Parameter
T

Parameters

ParameterType
valueT
...__namedParameters[null] extends [T] ? [string] : ["The assertion is useless because the provided value does not contain null."]

Returns

asserts value is Exclude<T, null>

Defined in

functions/assert.ts:30