API reference@evolu/commonType › map

function map<KeyType, ValueType>(
  key: ValidateMapKeyType<KeyType>,
  value: ValidateMapValueType<ValueType>,
): MapType<KeyType, ValueType>;

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

Map Type whose keys and values must match their respective Types.

Maps from this or another realm are accepted. A Map must have no own properties; its entries are validated in iteration order. When distinct input keys decode to the same output key, validation fails instead of discarding one associated value. Classification uses the realm-neutral object tag under Evolu Type's trusted JavaScript policy.

Example

import { assertOk, PositiveInt, String, map } from "@evolu/common";

const Scores = map(String, PositiveInt);
const scores = new Map([
  ["Ada", 10],
  ["Grace", 20],
]);

assertOk(Scores.fromUnknown(scores), scores);