mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-15 03:23:08 -06:00
Contextual this in 'obj.xxx = function(...)' or 'obj[xxx] = function(...)'
This commit is contained in:
parent
27346b13d0
commit
e3a0687327
@ -11518,6 +11518,14 @@ namespace ts {
|
||||
// for 'this' is the type of the object literal itself.
|
||||
return checkExpressionCached(containingLiteral);
|
||||
}
|
||||
// In an assignment of the form 'obj.xxx = function(...)' or 'obj[xxx] = function(...)', the
|
||||
// contextual type for 'this' is 'obj'.
|
||||
if (func.parent.kind === SyntaxKind.BinaryExpression && (<BinaryExpression>func.parent).operatorToken.kind === SyntaxKind.EqualsToken) {
|
||||
const target = (<BinaryExpression>func.parent).left;
|
||||
if (target.kind === SyntaxKind.PropertyAccessExpression || target.kind === SyntaxKind.ElementAccessExpression) {
|
||||
return checkExpressionCached((<PropertyAccessExpression | ElementAccessExpression>target).expression);
|
||||
}
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user