Skip to content

Commit 8e232e4

Browse files
committed
Limit this.foo(...) reachability checks to explicit this types
1 parent 2e985e7 commit 8e232e4

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/compiler/checker.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17135,7 +17135,7 @@ namespace ts {
1713517135
const symbol = getResolvedSymbol(<Identifier>node);
1713617136
return getExplicitTypeOfSymbol(symbol.flags & SymbolFlags.Alias ? resolveAlias(symbol) : symbol);
1713717137
case SyntaxKind.ThisKeyword:
17138-
return checkThisExpression(node);
17138+
return getExplicitThisType(node);
1713917139
case SyntaxKind.PropertyAccessExpression:
1714017140
const type = getTypeOfDottedName((<PropertyAccessExpression>node).expression);
1714117141
const prop = type && getPropertyOfType(type, (<PropertyAccessExpression>node).name.escapedText);
@@ -18720,6 +18720,20 @@ namespace ts {
1872018720
}
1872118721
}
1872218722

18723+
function getExplicitThisType(node: Expression) {
18724+
const container = getThisContainer(node, /*includeArrowFunctions*/ false);
18725+
if (isFunctionLike(container)) {
18726+
const signature = getSignatureFromDeclaration(container);
18727+
if (signature.thisParameter) {
18728+
return getExplicitTypeOfSymbol(signature.thisParameter);
18729+
}
18730+
}
18731+
if (isClassLike(container.parent)) {
18732+
const symbol = getSymbolOfNode(container.parent);
18733+
return hasModifier(container, ModifierFlags.Static) ? getTypeOfSymbol(symbol) : (getDeclaredTypeOfSymbol(symbol) as InterfaceType).thisType!;
18734+
}
18735+
}
18736+
1872318737
function getClassNameFromPrototypeMethod(container: Node) {
1872418738
// Check if it's the RHS of a x.prototype.y = function [name]() { .... }
1872518739
if (container.kind === SyntaxKind.FunctionExpression &&

0 commit comments

Comments
 (0)