Skip to content

In JS, fix contextual type of this-property assignments #26743

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

Merged
merged 1 commit into from
Aug 29, 2018

Conversation

sandersn
Copy link
Member

in object literal methods inside an object literal with a type annotation.

Note that this does not change:

  1. The type of this in object literal methods. The new baselines show that it's incorrect in this case.
  2. The fact that this-property assignments are still declarations. They just don't block contextual typing like most declarations do. [1]

This change is a bit expensive. It first calls getThisContainer, which walks the tree upward. Then it calls checkThisExpression, which will usually call getContextualType on the object literal method. If the new code then returns true, it will proceed to redo much of that work.

Calling checkThisExpression should not cause incorrect circularity failures; we only have to inspect the shape of the object literal and not the types of its properties to determine its type.

Fixes #25926

[1] The binder marks this-property assignments as declarations, and has to do so using local information.

in object literal methods inside an object literal with a type
annotation.

Note that this does not change:

1. The type of `this` in object literal methods.
2. The fact that this-property assignments are still declarations. They
just don't block contextual typing like most declarations do.

This change is a bit expensive. It first calls getThisContainer, which
walks the tree upward. Then it calls checkThisExpression, which will
usually call getContextualType on the object literal method. If the new
code then returns true, it will proceed to redo much of that work.

Calling checkThisExpression should not cause incorrect circularity
failures; we only have to inspect the shape of the object literal and
not the types of its properties to determine its type.
@sandersn sandersn requested review from a user and weswigham August 29, 2018 20:58
@ghost
Copy link

ghost commented Aug 29, 2018

Related issue: #26748

@sandersn sandersn merged commit 29dbabe into master Aug 29, 2018
@sandersn sandersn deleted the js/fix-contextual-type-of-this-assignments branch August 29, 2018 22:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant