-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Fix circular mapped type instantiations for arrays and tuples #27911
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
Conversation
!!! error TS2322: Type '{ a: number; }' is not assignable to type '{ a?: undefined; b?: undefined; }'. | ||
!!! error TS2322: Types of property 'a' are incompatible. | ||
!!! error TS2322: Type 'number' is not assignable to type 'undefined'. | ||
!!! error TS2322: Type '{ a: number; }' is not assignable to type '{ a: number; b: number; }'. |
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.
any idea why this changes? I don't see any mapped types here.
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.
Never mind, didn't see the change to discriminant types.
@@ -14212,12 +14222,26 @@ namespace ts { | |||
return undefined; | |||
} | |||
|
|||
function isDiscriminantType(type: Type): boolean { |
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 seems unrelated to the bug fix in the PR description
} | ||
let combined = 0; | ||
for (const t of (<UnionType>type).types) combined |= t.flags; | ||
if (combined & TypeFlags.Unit && !(combined & TypeFlags.Instantiable)) { |
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.
what happens if you have two two non-unit types? Should that still be discriminable?
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'm pretty sure this change isn't supposed to be here, since it's #27695
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.
Couple of questions
I accidentally based this PR on the |
Mapped types can circularly reference themselves (because member resolution is deferred), but array and tuple type instantiations cannot. This causes an issue when a circular homomorphic mapped type is instantiated for an array or tuple type as we now create array and tuple instantiations for such mappings (see #26063). With is PR we quickly detect and stop the runaway recursion that can occur by substituting
errorType
for the instantiation. We would eventually do this after 50 levels of nested instantiations, but exponential recursive fan-out could keep us from ever getting there.Fixes #27881.