-
Notifications
You must be signed in to change notification settings - Fork 12.8k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Allow any key type as an index signature parameter type #26797
Allow any key type as an index signature parameter type #26797
Conversation
@typescript-bot test this |
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
@RyanCavanaugh I see you marked this for TS 3.2. Is that still the plan? |
…s when a type literal
@typescript-bot pack this |
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 |
Hello, I found this PR and I am looking forward to its release. A question about this PR. type NumStr = `${number}`
type Obj = { [key: `${NumStr}`]: string }
const obj: 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'. |
Could this support optional indexers? This seems to work with the
|
@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 |
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