API reference / @evolu/common / Assert / assert
Variable: assert()
const assert: (condition, message) => asserts condition;
Defined in: packages/common/src/Assert.ts:43
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 length = buffer.getLength();
// We know length is logically non-negative, but TypeScript doesn't
assert(
NonNegativeInt.is(length),
"buffer length should be non-negative",
);
Parameters
Parameter | Type |
---|---|
condition | unknown |
message | string |
Returns
asserts condition