API reference › @evolu/common › Type › assertType

Call Signature

function assertType<Actual, Expected>(
  ...error: IsSameType<Actual, Expected> extends true
    ? []
    : [
        error: "⛔ assertType error: Actual and expected types must be identical",
      ]
): void;

Defined in: packages/common/src/Type.ts:1340

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's expectTypeOf(...).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 extends TypeNode>(
  type: T,
  value: unknown,
): asserts value is T["Output"];

Defined in: packages/common/src/Type.ts:1350

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's expectTypeOf(...).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">
>();