API reference › @evolu/common › Assert › assert
const assert: (
condition: unknown,
message: string,
options?: {
actual?: unknown;
cause?: unknown;
diff?: "full";
expected?: unknown;
operator?: string;
stackStartFn?: (...args: never[]) => unknown;
},
) => asserts condition;
Defined in: packages/common/src/Assert.ts:88
Asserts that a condition is truthy.
Throws an AssertionError with the provided message if the condition is
falsy, preventing invalid state from propagating and making the failure
easier to diagnose.
Use assert only when a more specific assertion, such as assertTrue
or assertEqual, does not apply. For that reason, assert requires a
custom message explaining the expected condition.
Options provide structured diagnostics for custom assertions. Pass an
underlying failure as cause when it explains why the asserted condition
failed, and pass the custom assertion as stackStartFn to omit its
implementation from the stack trace.
Example
import { assert, assertEqual, assertType } from "@evolu/common";
const value: unknown = "Evolu";
assert(typeof value === "string", "Expected a string.");
assertType<typeof value, string>();
assertEqual(value, "Evolu");