API reference@evolu/commonTypes › Instance

Defined in: packages/common/src/Types.ts:208

Realm-neutral runtime identity for a TypeScript interface.

Extend this interface and add its runtime evidence with instance when constructing a value. Unlike JavaScript instanceof, the identity does not depend on a constructor or prototype and therefore survives realms, package duplication, object spreading, and structured cloning.

The marker is intentionally forgeable. It identifies values created by trusted constructors; it is not structural validation or a security boundary.

Adding runtime identity

import { assertEqual, instance, type Instance } from "@evolu/common";

interface Foo extends Instance<"Foo"> {
  readonly value: string;
}

const foo: Foo = {
  ...instance("Foo"),
  value: "value",
};

assertEqual(foo["~evolu/instance"], "Foo");

Properties

~evolu/instance

readonly ~evolu/instance: Name;

Defined in: packages/common/src/Types.ts:209