Suggestion
🔍 Search Terms
✅ Viability Checklist
My suggestion meets these guidelines:
⭐ Suggestion
Since pattern literal types like `${number}` are valid as of #40598, I feel like there should be an option to make:
typeArrayLikeKeys=keyofArrayLike<any>;
result in:
typeArrayLikeKeys="length"| `${number}`;The same should happen for any numeric property key:
interfaceFoo{1: "a";2: "b";3: "c";}// Currently is: : 1 | 2 | 3// Should be: "1" | "2" | "3"typeKeyOfFoo=keyofFoo;// Currently is: nevertypeStrictKeyOfFoo=(keyofFoo)&(string|symbol);like with:
interfaceFoo{"1": "a";"2": "b";"3": "c";}// Is: "1" | "2" | "3"typeKeyOfFoo=keyofFoo;📃 Motivating Example
This makes keyof and numeric index signatures match runtime behaviour.
💻 Use Cases
Currently, it’s necessary to use the strictKeyof and StrictPropertyKey helpers:
typestrictKeyof<T>=keyofTextends infer K
? (Kextendsnumber ? `${K}` : K)
: never;typeStrictPropertyKey=string|symbol;Relevant issues:
This will most likely depend on #26797, so that treating numeric index signatures as numeric pattern literal index signatures is valid:
interfaceArrayLike<T>{readonly[index: `${number}`]: T;readonlylength: number;}
Suggestion
🔍 Search Terms
✅ Viability Checklist
My suggestion meets these guidelines:
⭐ Suggestion
Since pattern literal types like
`${number}`are valid as of #40598, I feel like there should be an option to make:result in:
The same should happen for any numeric property key:
like with:
📃 Motivating Example
This makes
keyofand numeric index signatures match runtime behaviour.💻 Use Cases
Currently, it’s necessary to use the
strictKeyofandStrictPropertyKeyhelpers:Relevant issues:
ProxyHandler#35594 (comment), fix(lib/es2015): Fix definition ofProxyHandler#35594 (comment), fix(lib/es2015): Fix definition ofProxyHandler#35594 (comment)Reflectmethods #41987This will most likely depend on #26797, so that treating numeric index signatures as numeric pattern literal index signatures is valid: