Skip to content

gaslamp


Function: assert()

assert\<T>(value, guard, options?): asserts value is T

Assert that a value matches a guard, narrowing its type in-place.

Use when you need TypeScript to narrow the type of an existing variable without reassigning it.

Type Parameters

T

T

Parameters

value

unknown

Value to assert

guard

Flame\<T>

Type guard to apply

options?

FlameOptions

Optional context for error messages

Returns

asserts value is T

Throws

TypeError if the guard returns false

Example

TypeScript
assert(input, FlameGuards.isNumber, { at: "calcTotal", label: "price" });
Logger.log(input * 1.1); // input is typed as number

Since

0.37.0