API reference › @evolu/common › Type › assertType
Call Signature
function assertType<Actual, Expected>(
...error: IsSameType<Actual, Expected> extends true
? []
: ["⛔ assertType error: Actual and expected types must be identical"]
): void;
Defined in: packages/common/src/Type.ts:1191
Asserts type equality or validates a value with a Type.
assertType<Actual, Expected>()requires compiler-identical types without evaluating a value. It is Evolu's platform-agnostic equivalent of Vitest'sexpectTypeOf(...).toEqualTypeOf<...>()and does not require a test runner.assertType(type, value)validates and narrows a runtime value to the Type's Output.
Use the runtime form for code-correctness invariants, not expected validation
failures. Validate external input with Type.fromUnknown so validation
failures remain typed values.
Example
import {
NonEmptyTrimmedString100,
assertType,
type Brand,
} from "@evolu/common";
const value: unknown = "Evolu";
assertType(NonEmptyTrimmedString100, value);
assertType<
typeof value,
string & Brand<"Trimmed"> & Brand<"MinLength1"> & Brand<"MaxLength100">
>();
Call Signature
function assertType<T>(type: T, value: unknown): asserts value is T["Output"];
Defined in: packages/common/src/Type.ts:1201
Asserts type equality or validates a value with a Type.
assertType<Actual, Expected>()requires compiler-identical types without evaluating a value. It is Evolu's platform-agnostic equivalent of Vitest'sexpectTypeOf(...).toEqualTypeOf<...>()and does not require a test runner.assertType(type, value)validates and narrows a runtime value to the Type's Output.
Use the runtime form for code-correctness invariants, not expected validation
failures. Validate external input with Type.fromUnknown so validation
failures remain typed values.
Example
import {
NonEmptyTrimmedString100,
assertType,
type Brand,
} from "@evolu/common";
const value: unknown = "Evolu";
assertType(NonEmptyTrimmedString100, value);
assertType<
typeof value,
string & Brand<"Trimmed"> & Brand<"MinLength1"> & Brand<"MaxLength100">
>();