Skip to content

Function: assert() ​

ts
function assert<T>(
   condition: T, 
   format: string, ...
   rest: AnyArgs): asserts condition;

Assertion function to ensure provided condition is truthy. Raises a formatted error when the condition is falsy.

Type Parameters ​

Type ParameterDefault type
Tboolean

Parameters ​

ParameterTypeDescription
conditionTCondition to assert.
formatstringC-like formatted string for interpolation.
...restAnyArgsRest parameters to interpolate into format string.

Returns ​

asserts condition

Remarks ​

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