Record with number as key?

const A = type("Record<number, string>");
const A = type("Record<number, string>");
This throws error:
Argument of type '"Record<number, string>"' is not assignable to parameter of type '"K must be assignable to string | symbol (was number) "'
Argument of type '"Record<number, string>"' is not assignable to parameter of type '"K must be assignable to string | symbol (was number) "'
But it should be valid:
type A = Record<number, string>;
type A = Record<number, string>;
4 Replies
SynthLuvr
SynthLuvr3w ago
Also:
const B = ark.Record("number", "number");
const B = ark.Record("number", "number");
Argument of type '["number", "number"]' is not assignable to parameter of type '["number", "number"] & [ErrorType<"Invalid argument for K", [expected: Key]>, unknown]'.
Type '["number", "number"]' is not assignable to type '[ErrorType<"Invalid argument for K", [expected: Key]>, unknown]'.
Type at position 0 in source is not compatible with type at position 0 in target.
Type 'string' is not assignable to type 'ErrorType<"Invalid argument for K", [expected: Key]>'
Argument of type '["number", "number"]' is not assignable to parameter of type '["number", "number"] & [ErrorType<"Invalid argument for K", [expected: Key]>, unknown]'.
Type '["number", "number"]' is not assignable to type '[ErrorType<"Invalid argument for K", [expected: Key]>, unknown]'.
Type at position 0 in source is not compatible with type at position 0 in target.
Type 'string' is not assignable to type 'ErrorType<"Invalid argument for K", [expected: Key]>'
TizzySaurus
TizzySaurus3w ago
It's not possible to have numbers as a key in JS
TizzySaurus
TizzySaurus3w ago
Numbers are implicitly converted to strings
No description
ssalbdivad
ssalbdivad3w ago
You could do Record<string.numeric, string> But yeah it was a big mistake for TS to include numeric keys that don't reflect a real language feature so that's an area where I'm consciously diverging
Want results from more Discord servers?
Add your server