-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
Add static index signature #37797
Add static index signature #37797
Conversation
@typescript-bot pack this. |
Hey @Kingwl, I've packed this into an installable tgz. You can install it for testing by referencing it in your
and then running |
@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. |
@weswigham the reviewer list is broken on this PR, but you should look at this too |
⬆️ |
src/compiler/checker.ts
Outdated
@@ -9664,6 +9677,13 @@ namespace ts { | |||
} | |||
} | |||
|
|||
function getIndexInfoOfIndexSymbol(indexSymbol: Symbol, indexKind: IndexKind) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is used only once in the above changed code, maybe make it a local helper instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I kinda prefer it this way to avoid several closure allocations, but it's likely a premature optimization.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(I'd be surprised if at least the v8 compiler wouldn't optimize it away...)
src/compiler/checker.ts
Outdated
@@ -11094,24 +11114,29 @@ namespace ts { | |||
} | |||
|
|||
function getIndexSymbol(symbol: Symbol): Symbol | undefined { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're splitting both getIndexSymbol
and getIndexDeclarationOfSymbol
to two functions each, because your code calls them with different inputs, and it's the only place that needs the two new entry points. One such refactor seems questionable, but two looks like too much. (But OTOH I can't figure out if there's a way to avoid it.)
Ping @DanielRosenwasser, @weswigham. |
Hi, Folks, I don't know what I can do. Should I work with the parser issue inside this PR? |
I would say no - though, if you want to tackle the problem, coordinate with @rbuckton on #38283. Otherwise, I'm not familiar enough with the internals. @elibarzilay and @weswigham, can you give this another review? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The implementation looks good, but I'd love to see some more tests (you should consider placing them in a subfolder of the conformance
directory instead of compiler
, since it's a "new" language feature). Specifically, I'm thinking of tests showing:
- Class static inheritance both inheriting and overriding index signatures (and issuing errors if you override with an incompatible type)
- Assignability of class static sides to one another when index signatures are in place (readonly and not readonly)
- Assignability between class static sides and equivalent interfaces describing them
- Assignability between class static sides with generic static index signatures (this likely requires defining classes within a closure with generic parameters) to have some sanity checks on the behavior of variance digests with these
- Some usages with indexed access types, eg
(typeof Cls)[string]
- Some usages with
keyof
, egkeyof typeof Cls
- Some usages with homomorphic mapped types, eg
Extract<typeof Cls, string>
More would also be welcome, ofc, if you can think of any other possible edge cases.
@elibarzilay @weswigham I'd like to get this in early in the 4.3 cycle. Does this (1) have enough tests now (2) error correctly on property types? |
Friendly ping 👀 |
👀PiNg AgAiN |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Assuming my question is answered, I think this is probably good now, with @sandersn 's questions both answering in the affirmative. @elibarzilay since you're the PR assignee, you can probably merge this for this cycle whenever you're ready.
just for verify @typescript-bot pack this. |
Hey @Kingwl, I've packed this into an installable tgz. You can install it for testing by referencing it in your
and then running |
Hrm, I'm not certain why the playground didn't build (as this seems to be completely up to date with master), I'll look into add some more logs in the build process. |
Try again. |
Hey @Kingwl, 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 |
Fixes #6480