API reference › @evolu/common › Type › assertType
Call Signature
function assertType<Expected, Actual>(
...error: IsSameType<Expected, Actual> extends true
? []
: ["⛔ assertType error: Expected and actual types must be identical"]
): void;
Defined in: packages/common/src/Type.ts:1073
Asserts exact compile-time type equality or that a value belongs to a Type Output domain.
assertType<Expected, Actual>()requires compiler-identical types without evaluating a value.assertType(type, value)validates and narrows a runtime value to the Type's Output.
Use the runtime form for internal invariants, not external input. Validate
external input with Type.fromUnknown so validation failures remain typed
values. A failed runtime assertion uses the Type name for its message and
preserves the exact Output validation error as the thrown Error's cause.
Example
import {
NonEmptyTrimmedString100,
assertType,
type Brand,
} from "@evolu/common";
const value: unknown = "Evolu";
assertType(NonEmptyTrimmedString100, value);
assertType<
string & Brand<"Trimmed"> & Brand<"MinLength1"> & Brand<"MaxLength100">,
typeof value
>();
Call Signature
function assertType<T>(type: T, value: unknown): asserts value is T["Output"];
Defined in: packages/common/src/Type.ts:1083
Asserts exact compile-time type equality or that a value belongs to a Type Output domain.
assertType<Expected, Actual>()requires compiler-identical types without evaluating a value.assertType(type, value)validates and narrows a runtime value to the Type's Output.
Use the runtime form for internal invariants, not external input. Validate
external input with Type.fromUnknown so validation failures remain typed
values. A failed runtime assertion uses the Type name for its message and
preserves the exact Output validation error as the thrown Error's cause.
Example
import {
NonEmptyTrimmedString100,
assertType,
type Brand,
} from "@evolu/common";
const value: unknown = "Evolu";
assertType(NonEmptyTrimmedString100, value);
assertType<
string & Brand<"Trimmed"> & Brand<"MinLength1"> & Brand<"MaxLength100">,
typeof value
>();