Skip to content

Function: ensureExists()

ensureExists<T>(value, message?): T

Defined in: helpers/ensure.ts:51

Helper to check that a given value is defined, that is, is neither undefined nor null. If the value is undefined or null, an error will be raised at runtime.

This is typically used to inform TypeScript that you expect a given value to always exist. Calling this function refines a type that can otherwise be null or undefined.

Type Parameters

Type Parameter
T

Parameters

Parameter Type
value T | null | undefined
message? string

Returns

T