Skip to content

Function: assertDefined()

ts
function assertDefined<T>(
   value: Nillable<T>, 
   format?: string, ...
   rest: AnyArgs): asserts value is T;

Assertion function to ensure provided value is not nil.

Type Parameters

Type Parameter
T

Parameters

ParameterTypeDefault valueDescription
valueNillable<T>undefinedValue to check.
formatstring"Type assertion failed, unexpected 'nil' value provided."Optional C-like formatted string for interpolation.
...restAnyArgsundefinedRest parameters to interpolate into format string.

Returns

asserts value is T

Remarks

@inline keeps the happy path as a local if check and avoids a function call at runtime.