-
Notifications
You must be signed in to change notification settings - Fork 12.8k
this
in object literals intersects contextual type and literal type
#8356
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
@@ -8450,6 +8453,12 @@ namespace ts { | |||
if ((isFunctionExpressionOrArrowFunction(func) || isObjectLiteralMethod(func)) && | |||
isContextSensitive(func) && | |||
func.kind !== SyntaxKind.ArrowFunction) { | |||
const type = isObjectLiteralMethod(func) |
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 logic is duplicated between here and getContextualSignature. consider refactoring it.
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.
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.
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? |
Also |
@yuit published then unpublished a package. |
👍 |
Fixes #8191
any
, its contextualthis
type is nowany
as well.x.prototype.y = function () { ... }
pattern override the contextual type.