Is there a recommended way to create a Record using a type as a key?
None of these seem to work:
4 Replies
I get the error
ParseError: Index keys "CAR", "DEV", "ECO", "ENDO", "GEN", "IMM", "IRR", "NEU", "ORG", "REP", "RES" should be specified as named props.Yeah unfortunately this was a mistake in how the parser was implemented to ensure named properties are normalized in their representation:
https://github.com/arktypeio/arktype/issues/952
The easiest thing to do for now would probably just be to define that initial set of keys as a tuple, then you can map it with
Object.fromEntries to build the type you want.GitHub
Allow index node to be parsed from enumerable keys · Issue #952 · a...
Currently, an index signature including a literal key like "a" is an error due to some limitations of how the parser is implemented. There is a normalizeIndexKey function, but it is not u...
It is a bit embarrassing that I have to ask - but how does that workaround work? I tried a few things with Object.fromEntries but could never get it to work. I am missing something obvious here, sorry. Does anyone have a working example for something like
Record<"A" | "B", number | null>?Something like this should do what you want: