- Notifications
You must be signed in to change notification settings - Fork 13.2k
Allow any key type as an index signature parameter type#26797
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow any key type as an index signature parameter type #26797
Uh oh!
There was an error while loading. Please reload this page.
Conversation
weswigham commented Aug 30, 2018 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
weswigham commented Aug 30, 2018
@typescript-bot test this |
typescript-bot commented Aug 30, 2018 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
Heya @weswigham, I've started to run the extended test suite on this PR at 2c47d31. You can monitor the build here. It should now contribute to this PR's status checks. |
(2) typescript 2.9 not allow symbol to be used as index. microsoft/TypeScript#1863. Current there is a PR open to address this issue microsoft/TypeScript#26797
jhpratt commented Nov 22, 2018
@RyanCavanaugh I see you marked this for TS 3.2. Is that still the plan? |
orta commented Mar 18, 2021
@typescript-bot pack this |
typescript-bot commented Mar 18, 2021 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
typescript-bot commented Mar 18, 2021 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
Hey @orta, I've packed this into an installable tgz. You can install it for testing by referencing it in your and then running There is also a playground for this build and an npm module you can use via |
nana4gonta commented Mar 30, 2021 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
Hello, I found this PR and I am looking forward to its release. A question about this PR. typeNumStr= `${number}` typeObj={[key: `${NumStr}`]: string}constobj: Obj={"0xff": "",// OK"100e10": "",// OK"100": "",// NG, but why?}// Type '{"0xff": string; "100e10": string; "100": string}' is not assignable to type 'Obj'.// Object literal may only specify known properties, and '"100"' does not exist in type 'Obj'. |
RyanCavanaugh commented May 24, 2021
mykohsu commented Jun 4, 2021 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
Could this support optional indexers? This seems to work with the |
MartinJohns commented Jul 12, 2021
@weswigham What's the status of this? The PR is still open and has the "Backlog" milestone, yet on the roadmap it's marked as done and already part of |
ahejlsberg commented Jul 12, 2021
It's been superseded by #44512. |
This allows, eg,
symbol:enums:
literal unions:
and generics:
as index signature parameter types.
Much of this functionality also exists in mapped types, except they had trouble shuffling around symbol information since there was no kind of index signature a symbol could map to. Unlike mapped types, however, since these are just index signatures, they can be added into any object type and in multiples.
Fixes#26470
Fixes#1863 (caveat: well-known symbols are not currently checked as part of a symbol index signature! Such checking should fall out from removing the concept of well-known symbols and using unique symbols instead)
Fixes#2491 in the original sense (rather than with mapped types).
Related: #28315