@@ -3063,9 +3063,14 @@ namespace ts {
3063
3063
}
3064
3064
}
3065
3065
// 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
+ }
3069
3074
if (type) {
3070
3075
return addOptionality(type, /*optional*/ declaration.questionToken && includeOptionality);
3071
3076
}
@@ -4689,6 +4694,9 @@ namespace ts {
4689
4694
if (isJSConstructSignature) {
4690
4695
minArgumentCount--;
4691
4696
}
4697
+ if (!thisParameter && isObjectLiteralMethod(declaration)) {
4698
+ thisParameter = getContextuallyTypedThisParameter(declaration);
4699
+ }
4692
4700
4693
4701
const classType = declaration.kind === SyntaxKind.Constructor ?
4694
4702
getDeclaredTypeOfClassOrInterface(getMergedSymbol((<ClassDeclaration>declaration.parent).symbol))
@@ -9087,10 +9095,6 @@ namespace ts {
9087
9095
if (thisType) {
9088
9096
return thisType;
9089
9097
}
9090
- const type = getContextuallyTypedThisType(container);
9091
- if (type) {
9092
- return type;
9093
- }
9094
9098
}
9095
9099
if (isClassLike(container.parent)) {
9096
9100
const symbol = getSymbolOfNode(container.parent);
@@ -9326,11 +9330,11 @@ namespace ts {
9326
9330
}
9327
9331
}
9328
9332
9329
- function getContextuallyTypedThisType (func: FunctionLikeDeclaration): Type {
9333
+ function getContextuallyTypedThisParameter (func: FunctionLikeDeclaration): Symbol {
9330
9334
if (isContextSensitiveFunctionOrObjectLiteralMethod(func) && func.kind !== SyntaxKind.ArrowFunction) {
9331
9335
const contextualSignature = getContextualSignature(func);
9332
9336
if (contextualSignature) {
9333
- return getThisTypeOfSignature( contextualSignature) ;
9337
+ return contextualSignature.thisParameter ;
9334
9338
}
9335
9339
}
9336
9340
0 commit comments