-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Fix circularity errors in intra-binding-pattern references #59183
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
@typescript-bot test it |
Hey @ahejlsberg, the results of running the DT tests are ready. Everything looks the same! |
@ahejlsberg Here they are:
tscComparison Report - baseline..pr
System info unknown
Hosts
Scenarios
Developer Information: |
@ahejlsberg Here are the results of running the user tests with tsc comparing Something interesting changed - please have a look. Details
|
@ahejlsberg Here are the results of running the top 400 repos with tsc comparing Something interesting changed - please have a look. Details
|
@typescript-bot test it |
Hey @ahejlsberg, the results of running the DT tests are ready. Everything looks the same! |
@ahejlsberg Here are the results of running the user tests with tsc comparing Something interesting changed - please have a look. Details
|
@ahejlsberg Here they are:
tscComparison Report - baseline..pr
System info unknown
Hosts
Scenarios
Developer Information: |
@ahejlsberg Here are the results of running the top 400 repos with tsc comparing Everything looks good! |
Tests are all clean and performance is unaffected. I think this is good to merge. |
@@ -104,8 +104,8 @@ type Something = { foo: number }; | |||
|
|||
// inference fails here, but ideally should not | |||
const A = object<Something>()({ | |||
>A : ObjectType<Something> | |||
> : ^^^^^^^^^^^^^^^^^^^^^ | |||
>A : any |
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 previous type was better here but i guess maybe that relied on broken assumptions from the PR that got reverted
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.
Right, when we report circularity errors we also assign the error type, but the reverted PR sometimes didn't do that.
@ahejlsberg Thanks for this fix, and sorry my PR caused inconsistencies. ❤️ |
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.
We should follow up on the change in effect
. It looks correct on first glance but there might be some interplay with the outer contextual type in that example
@RyanCavanaugh The |
This PR reverts #56753 and implements a new fix for #49989.
Consider the example:
The array literal
[42]
is contextually typed by the implied type of the binding pattern. To compute the implied type, we substituteany
for for the first element (because it has no initializer) and the type ofa + 1
for the second element. However, to compute the type ofa + 1
we need the type ofa
, which in turn means we need the type of[42][0]
, which means we need to know the type of the array literal[42]
, which is contextually typed by the implied type of the binding pattern... and we have a circularity.In #56753, logic was introduced that silently squelches circularity errors, but that isn't feasible because it is highly dependent on resolution order. In this PR we instead introduce logic that detects intra-binding-pattern references (such as the reference to
a
ina + 1
) and types them asany
when computing implied binding pattern types.Though strictly not necessary for the fix, the PR also revises the manner in which we "pad" types of initializer expressions for object destructuring patterns. This used to happen in
checkObjectLiteral
but now happens incheckDeclarationInitializer
, aligning with the way we pad types of initializer expressions for array destructuring patterns. This change is responsible for the "Initializer provides no value for this binding element and the binding element has no default value" errors changing to messages like "Property 'a' does not exist on type '{}'" in the baselines.Fixes #49989.
Fixes #59177.