Skip to content

Commit f6a3a3f

Browse files
committed
Use '__this__' property in contextual type to indicate type of 'this'
1 parent f673f48 commit f6a3a3f

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

src/compiler/checker.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11189,6 +11189,19 @@ namespace ts {
1118911189
return getTypeOfSymbol(thisParameter);
1119011190
}
1119111191
}
11192+
if (isObjectLiteralMethod(func)) {
11193+
// For methods in an object literal, look for a '__this__' property in the contextual
11194+
// type for the object literal. If one exists, remove 'undefined' from the type of that
11195+
// property and report it as the contextual type for 'this' in the method.
11196+
const objectLiteral = <ObjectLiteralExpression>func.parent;
11197+
const type = getApparentTypeOfContextualType(objectLiteral);
11198+
if (type) {
11199+
const propertyType = getTypeOfPropertyOfContextualType(type, "___this__");
11200+
if (propertyType) {
11201+
return getNonNullableType(propertyType);
11202+
}
11203+
}
11204+
}
1119211205
}
1119311206
return undefined;
1119411207
}

0 commit comments

Comments
 (0)