arktypea
arktype13mo ago
francis

Is there a recommended way to create a Record using a type as a key?

None of these seem to work:
const stringKeys = type(
  "===",
  "CAR",
  "ENDO",
  "REP",
  "DEV",
  "GEN",
  "NEU",
  "ORG",
  "IMM",
  "RES",
  "IRR",
  "ECO",
);

const explicit = type.Record(stringKeys, type("number | null"));

const stringSyntax = type(
  'Record<"CAR" | "ENDO" | "REP" | "DEV" | "GEN" | "NEU" | "ORG" | "IMM" | "RES" | "IRR" | "ECO", number | null>',
);
Was this page helpful?