You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
An alternative option to keyofStringsOnly that stringifies numeric properties and index signatures #43041
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:
Activity