-
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
Fixed contextual types within generic tuple mapped types #53042
base: main
Are you sure you want to change the base?
Fixed contextual types within generic tuple mapped types #53042
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
@@ -28959,6 +28959,15 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { | |||
return isCircularMappedProperty(prop) ? undefined : getTypeOfSymbol(prop); | |||
} | |||
if (isTupleType(t) && isNumericLiteralName(name) && +name >= 0) { | |||
if (t.target.hasRestElement) { |
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 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
It's a case that I came up with when reviewing #53036