API reference › @evolu/common › Assert › assert
const assert: (condition: unknown, message: string) => 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.
Do not use this instead of Type. Assertions are intended when a condition is logically guaranteed to be true but TypeScript cannot prove it, or for catching and signaling developer mistakes eagerly.
Example
import { assert, assertEqual, assertErr, trySync } from "@evolu/common";
assert(true, "Expected true.");
const result = trySync(() => assert(false, "Expected true."));
assertErr(result);
assert(result.error instanceof Error, "Expected an Error.");
assertEqual(result.error.message, "Expected true.");