Fixed contextual types within generic tuple mapped types#53042
Fixed contextual types within generic tuple mapped types#53042Andarist wants to merge 4 commits intomicrosoft:mainfrom
Conversation
|
This PR doesn't have any linked issues. Please open an issue that references this PR. From there we can discuss and prioritise. |
|
This is the comment where you describe the bug, right? |
|
Yep, it mentions this and related things |
src/compiler/checker.ts
Outdated
| return isCircularMappedProperty(prop) ? undefined : getTypeOfSymbol(prop); | ||
| } | ||
| if (isTupleType(t) && isNumericLiteralName(name) && +name >= 0) { | ||
| if (t.target.hasRestElement) { |
There was a problem hiding this comment.
The tuple type could be [...T] where T extends [] and, thus, should not have a contextual type for a numbered element (at all), so I'm not sure checking this field is correct.
src/compiler/checker.ts
Outdated
| if (t.target.hasRestElement) { | ||
| const restElement = getTypeArguments(t)[t.target.fixedLength]; | ||
| if (restElement !== type) { | ||
| const propType = getTypeOfPropertyOfContextualType(restElement, name); |
There was a problem hiding this comment.
Erm, name needs to be offset by the length of the preceding fixed elements of the tuple, no? And even that's thrown into question with multiple variadic tuple elements? Eg, if t is [...T, ...U] and name is 0, where T extends [] | [number] and U extends [] | [string], this is just going to lookup 0 on T, which is, at best, a partial result. (You'd want the contextual type to be something like string | number | undefined or something constrained to such). Seems like something a bit more complete is needed to handle variadic tuples fully.
…n-zipping-generic-tuples
…n-zipping-generic-tuples
cc2f135 to
eef042a
Compare
It's a case that I came up with when reviewing #53036