Type 'this' in object literal function properties

Previously, methods of object literals would give a type to 'this'.
Now function properties of object literals also give a type to 'this'.
This commit is contained in:
Nathan Shively-Sanders
2016-04-29 10:31:01 -07:00
parent 91201211f4
commit c12cb83fb7
20 changed files with 158 additions and 87 deletions

View File

@@ -8206,10 +8206,11 @@ namespace ts {
if (signature.thisType) {
return signature.thisType;
}
if (container.parent && container.parent.kind === SyntaxKind.ObjectLiteralExpression) {
const parentObject = container.parent && container.parent.kind === SyntaxKind.PropertyAssignment ? container.parent.parent : container.parent;
if (parentObject && parentObject.kind === SyntaxKind.ObjectLiteralExpression) {
// Note: this works because object literal methods are deferred,
// which means that the type of the containing object literal is already known.
const type = checkExpressionCached(<ObjectLiteralExpression>container.parent);
const type = checkExpressionCached(<ObjectLiteralExpression>parentObject);
if (type) {
return type;
}