-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Distribute 'keyof' union types #23626
Conversation
# Conflicts: # src/compiler/checker.ts # tests/baselines/reference/keyofAndIndexedAccessErrors.errors.txt # tests/baselines/reference/keyofAndIndexedAccessErrors.symbols
@@ -12,8 +12,8 @@ class C extends Base { | |||
>super : typeof Base | |||
|
|||
var obj = { | |||
>obj : { [x: string]: () => void; } | |||
>{ [(super(), "prop")]() { } } : { [x: string]: () => void; } | |||
>obj : { [(super(), "prop")](): void; } |
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.
So, I don't know if it's related to this PR, but this change caught my eye:
{ [(super(), "prop")](): void; }
isn't a valid type. Somewhere we're reusing the name's expression tree when building the computed property name type and shouldn't be. :(
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.
This is actually a baseline change from #23592. I somehow messed up a merge and ended up with a lot of apparent changes in this PR.
Anyways, what's not valid about the type? It's a method with a computed property name that uses the comma operator.
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.
That's supposed to be type output - if someone wrote type Foo = { [(super(), "prop")](): void; }
, we'd issue an error.
I somehow ended up with a bad merge on this branch so I'm abandoning this PR in favor of #23645. |
With this PR we transform
keyof
applied to a union type to an intersection ofkeyof
applied to each union constituent. In other words, we rewrite types of the formkeyof (A | B)
tokeyof A & keyof B
.Some examples:
This PR is the mirror image of #22300 and finally brings symmetry to the type eqivalences:
Why it took so long to figure out I don't know!
Fixes #23618.