this in object literals intersects contextual type and literal type#8356
Merged
this in object literals intersects contextual type and literal type#8356
this in object literals intersects contextual type and literal type#8356Conversation
src/compiler/checker.ts
Outdated
| if ((isFunctionExpressionOrArrowFunction(func) || isObjectLiteralMethod(func)) && | ||
| isContextSensitive(func) && | ||
| func.kind !== SyntaxKind.ArrowFunction) { | ||
| const type = isObjectLiteralMethod(func) |
Contributor
There was a problem hiding this comment.
this logic is duplicated between here and getContextualSignature. consider refactoring it.
Member
Author
There was a problem hiding this comment.
done, although it still does the work twice in the case that there is no contextualSignature.
1. Remove intersection code. The any-defaulting code means that it's never hit. 2. Remove some code duplication.
If a contextual signature is found, if its thisType is undefined, then the contextual type of `this` is now `any`. Previously `checkThisExpression` would keep looking for a different type for `this`. Also update tests to show this new behaviour.
Member
Author
|
OK, I changed the behaviour of contextual signatures that don't define @mhegazy I think this is a good compromise. Can you take a look? |
Member
Author
|
Also |
Contributor
|
@yuit published then unpublished a package. |
Contributor
|
👍 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #8191
any, its contextualthistype is nowanyas well.x.prototype.y = function () { ... }pattern override the contextual type.