API reference@evolu/commonType › Data

type Data =
  | undefined
  | null
  | string
  | number
  | bigint
  | boolean
  | ReadonlyArray<Data>
  | {
      [key: string]: Data;
    }
  | ReadonlySet<Data>
  | ReadonlyMap<Data, Data>
  | globalThis.Date
  | globalThis.Uint8Array;

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

Evolu's recursive platform-independent structured-cloneable data domain.

Data is intentionally limited to values supported by the structured clone algorithm, so it can be sent through APIs such as worker postMessage. It includes supported JavaScript primitives and the runtime representations defined by array, Object, set, map, Date, and Uint8Array. Array elements, Object properties, Set elements, and Map keys and values must also be Data. Cyclic and shared data graphs are supported. Raw ArrayBuffer values are excluded; represent bytes with a Uint8Array.

Functions, arbitrary class instances, and other behavioral objects are not Data. The structural representations follow the corresponding Evolu Type rules. As with every Type operation, classification assumes trusted application code or audited dependencies; it is not a security boundary for adversarial Proxies or forged built-in object tags.

TypeScript cannot express dense Arrays, exact property descriptors, object prototypes, or the absence of custom properties on built-ins. Use the runtime Data Type when a value crosses an unknown boundary.

Example

import { assertOk, assertSame, assertType, Data } from "@evolu/common";

const value: unknown = {
  user: { name: "Ada" },
  scores: new Map([["logic", 100]]),
  roles: new Set(["admin"]),
};
const result = Data.fromUnknown(value);

assertOk(result);
assertSame(result.value, value);
assertType<Data, typeof result.value>();