Skip to content

Commit 5aafc2c

Browse files
committed
Contextually type this in getDeclFromSig, not checkThisExpr
1 parent 0f483d6 commit 5aafc2c

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

src/compiler/checker.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3063,9 +3063,14 @@ namespace ts {
30633063
}
30643064
}
30653065
// Use contextual parameter type if one is available
3066-
const type = declaration.symbol.name === "this"
3067-
? getContextuallyTypedThisType(func)
3068-
: getContextuallyTypedParameterType(<ParameterDeclaration>declaration);
3066+
let type: Type;
3067+
if (declaration.symbol.name === "this") {
3068+
const thisParameter = getContextuallyTypedThisParameter(func);
3069+
type = thisParameter ? getTypeOfSymbol(thisParameter) : undefined;
3070+
}
3071+
else {
3072+
type = getContextuallyTypedParameterType(<ParameterDeclaration>declaration);
3073+
}
30693074
if (type) {
30703075
return addOptionality(type, /*optional*/ declaration.questionToken && includeOptionality);
30713076
}
@@ -4689,6 +4694,9 @@ namespace ts {
46894694
if (isJSConstructSignature) {
46904695
minArgumentCount--;
46914696
}
4697+
if (!thisParameter && isObjectLiteralMethod(declaration)) {
4698+
thisParameter = getContextuallyTypedThisParameter(declaration);
4699+
}
46924700

46934701
const classType = declaration.kind === SyntaxKind.Constructor ?
46944702
getDeclaredTypeOfClassOrInterface(getMergedSymbol((<ClassDeclaration>declaration.parent).symbol))
@@ -9087,10 +9095,6 @@ namespace ts {
90879095
if (thisType) {
90889096
return thisType;
90899097
}
9090-
const type = getContextuallyTypedThisType(container);
9091-
if (type) {
9092-
return type;
9093-
}
90949098
}
90959099
if (isClassLike(container.parent)) {
90969100
const symbol = getSymbolOfNode(container.parent);
@@ -9326,11 +9330,11 @@ namespace ts {
93269330
}
93279331
}
93289332

9329-
function getContextuallyTypedThisType(func: FunctionLikeDeclaration): Type {
9333+
function getContextuallyTypedThisParameter(func: FunctionLikeDeclaration): Symbol {
93309334
if (isContextSensitiveFunctionOrObjectLiteralMethod(func) && func.kind !== SyntaxKind.ArrowFunction) {
93319335
const contextualSignature = getContextualSignature(func);
93329336
if (contextualSignature) {
9333-
return getThisTypeOfSignature(contextualSignature);
9337+
return contextualSignature.thisParameter;
93349338
}
93359339
}
93369340

0 commit comments

Comments
 (0)