Skip to content

"Index keys should be specified as named props" when creating Record with keys of union typeΒ #1515

@rombolshak

Description

@rombolshak

Report a bug

πŸ”Ž Search Terms

Record, Records, Generics

🧩 Context

  • ArkType version: 2.1.20
  • TypeScript version (5.1+): 5.8.3
  • Other context you think may be relevant (JS flavor, OS, etc.):

πŸ§‘β€πŸ’» Repro

In TS I can create needed type as:

type Values = "aaa" | "bbb" | "ccc"
type Thing = Record<Values, number> 
const out: Thing = {
    aaa: 0,
    bbb: 2, 
    ccc: 4
};

TS Playground

When trying to create the same type in Ark, I get "Index keys "aaa", "bbb", "ccc" should be specified as named props."

import { type } from "arktype"

const values = type.enumerated("aaa", "bbb", "ccc");
const Thing = type.Record(values, "number"); // throws 

const out = Thing.assert({
    aaa: 0,
    bbb: 2,
    ccc: 4
})

ArkType Playground

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

Status

Done (merged or closed)

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions