API Reference / @evolu/common / Assert / assert

Variable: assert()

const assert: (condition, message) => asserts condition;

Defined in: packages/common/src/Assert.ts:40

Ensures a condition is true, throwing an error with the provided message if not.

Prevents invalid states from propagating through the system by halting execution when a condition fails, improving reliability and debuggability.

Warning: Do not use this instead of Type. Assertions are intended for conditions that are logically guaranteed but not statically known by TypeScript, or for catching and signaling developer mistakes eagerly (e.g., invalid configuration).

Example

assert(true, "true is not true"); // no-op
assert(false, "true is not true"); // throws Error

const size = fooSize - buffer.getLength();
// Ensure required type
assert(PositiveInt.is(size), "size is not positive int");

Parameters

ParameterType
conditionunknown
messagestring

Returns

asserts condition

Was this page helpful?