@@ -15515,8 +15515,8 @@ namespace ts {
15515
15515
return !node.typeParameters && !getEffectiveReturnTypeNode(node) && !!node.body && node.body.kind !== SyntaxKind.Block && isContextSensitive(node.body);
15516
15516
}
15517
15517
15518
- function isContextSensitiveFunctionOrObjectLiteralMethod (func: Node): func is FunctionExpression | ArrowFunction | MethodDeclaration {
15519
- return (isInJSFile(func) && isFunctionDeclaration(func) || isFunctionExpressionOrArrowFunction(func) || isObjectLiteralMethod(func)) &&
15518
+ function isContextSensitiveFunctionOrObjectLiteralMethodOrClassMethod (func: Node): func is FunctionExpression | ArrowFunction | MethodDeclaration {
15519
+ return (isInJSFile(func) && isFunctionDeclaration(func) || isFunctionExpressionOrArrowFunction(func) || isObjectLiteralMethod(func) || (noImplicitAny && isClassMethodInSubClass(func)) ) &&
15520
15520
isContextSensitiveFunctionLikeDeclaration(func);
15521
15521
}
15522
15522
@@ -23516,7 +23516,7 @@ namespace ts {
23516
23516
if (func.kind === SyntaxKind.ArrowFunction) {
23517
23517
return undefined;
23518
23518
}
23519
- if (isContextSensitiveFunctionOrObjectLiteralMethod (func)) {
23519
+ if (isContextSensitiveFunctionOrObjectLiteralMethodOrClassMethod (func)) {
23520
23520
const contextualSignature = getContextualSignature(func);
23521
23521
if (contextualSignature) {
23522
23522
const thisParameter = contextualSignature.thisParameter;
@@ -23576,7 +23576,7 @@ namespace ts {
23576
23576
// Return contextual type of parameter or undefined if no contextual type is available
23577
23577
function getContextuallyTypedParameterType(parameter: ParameterDeclaration): Type | undefined {
23578
23578
const func = parameter.parent;
23579
- if (!isContextSensitiveFunctionOrObjectLiteralMethod (func)) {
23579
+ if (!isContextSensitiveFunctionOrObjectLiteralMethodOrClassMethod (func)) {
23580
23580
return undefined;
23581
23581
}
23582
23582
const iife = getImmediatelyInvokedFunctionExpression(func);
@@ -23954,6 +23954,28 @@ namespace ts {
23954
23954
return getContextualTypeForObjectLiteralElement(node, contextFlags);
23955
23955
}
23956
23956
23957
+ function getContextualTypeForClassMethod(node: MethodDeclaration): Type | undefined {
23958
+ if (node.type || !isPropertyNameLiteral(node.name) || some(node.parameters, parameter => !!parameter.type)) {
23959
+ return undefined;
23960
+ }
23961
+
23962
+ const container = cast(node.parent, isClassLike);
23963
+ const heritageElement = getClassExtendsHeritageElement(container);
23964
+ Debug.assertIsDefined(heritageElement);
23965
+
23966
+ const baseType = getTypeOfNode(heritageElement);
23967
+ if (baseType === errorType) {
23968
+ return undefined;
23969
+ }
23970
+
23971
+ const basePropType = getTypeOfPropertyOfType(baseType, getTextOfPropertyName(node.name))
23972
+ if (!basePropType) {
23973
+ return undefined
23974
+ }
23975
+
23976
+ return basePropType
23977
+ }
23978
+
23957
23979
function getContextualTypeForObjectLiteralElement(element: ObjectLiteralElementLike, contextFlags?: ContextFlags) {
23958
23980
const objectLiteral = <ObjectLiteralExpression>element.parent;
23959
23981
const type = getApparentTypeOfContextualType(objectLiteral, contextFlags);
@@ -24089,6 +24111,7 @@ namespace ts {
24089
24111
function getApparentTypeOfContextualType(node: Expression | MethodDeclaration, contextFlags?: ContextFlags): Type | undefined {
24090
24112
const contextualType = isObjectLiteralMethod(node) ?
24091
24113
getContextualTypeForObjectLiteralMethod(node, contextFlags) :
24114
+ isClassMethodInSubClass(node) ? getContextualTypeForClassMethod(node) :
24092
24115
getContextualType(node, contextFlags);
24093
24116
const instantiatedType = instantiateContextualType(contextualType, node, contextFlags);
24094
24117
if (instantiatedType && !(contextFlags && contextFlags & ContextFlags.NoConstraints && instantiatedType.flags & TypeFlags.TypeVariable)) {
@@ -24420,7 +24443,7 @@ namespace ts {
24420
24443
// all identical ignoring their return type, the result is same signature but with return type as
24421
24444
// union type of return types from these signatures
24422
24445
function getContextualSignature(node: FunctionExpression | ArrowFunction | MethodDeclaration): Signature | undefined {
24423
- Debug.assert(node.kind !== SyntaxKind.MethodDeclaration || isObjectLiteralMethod(node));
24446
+ Debug.assert(node.kind !== SyntaxKind.MethodDeclaration || isObjectLiteralMethod(node) || isClassMethodInSubClass(node) );
24424
24447
const typeTagSignature = getSignatureOfTypeTag(node);
24425
24448
if (typeTagSignature) {
24426
24449
return typeTagSignature;
0 commit comments