API reference@evolu/commonType › objectKeys

function objectKeys<Key>(
  key: Key & ValidateOutput<Key>,
): <T>(type: T & ValidateOutput<T>) => ObjectKeysType<Key, T>;

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

Renames a strict object Type's encoded keys using a string codec.

The object declaration uses semantic keys. Each key must be a valid Output of the key Type. Its canonical encoding becomes the external property name. Decoding accepts those exact names; aliases and unknown properties are rejected. Values, optionality, and semantic Output stay with the object Type. Only the outer keys change. Nested field codecs keep their own behavior.

Construction rejects invalid schema keys, duplicate encodings, and key codecs that do not decode their encodings back to the declared keys. These are schema mistakes; invalid external values return normal Type errors. Error paths use the external names, including missing required properties.

Example

import {
  assertEqual,
  assertErr,
  assertOk,
  CamelCaseIdentifierFromConstantCaseIdentifier,
  object,
  objectKeys,
  optional,
  PortFromString,
  prefixed,
} from "@evolu/common";

const Key = prefixed("APP_")(CamelCaseIdentifierFromConstantCaseIdentifier);
const Settings = objectKeys(Key)(object({ port: optional(PortFromString) }));

const result = Settings.fromUnknown({ APP_PORT: "04000" });
assertOk(result, { port: 4000 });

assertEqual(Settings.to(result.value), { APP_PORT: "4000" });

assertErr(Settings.fromUnknown({ APP_POTR: "4000" }));