diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index e911d7fe7d2a3..3370bd613b900 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -9134,6 +9134,26 @@ namespace ts { if (type) { return addOptionality(type, /*isProperty*/ false, isOptional); } + if (isMethodDeclaration(func) && isClassLike(func.parent) + && (noImplicitAny || isInJSFile(func.parent))) { // TODO: Might want to fiddle with restrictions here + const k = func.parent; + const basetypes = getBaseTypes(getTypeOfSymbol(getSymbolOfNode(k)) as InterfaceType); // TODO: Assumption of prototype + if (basetypes.length === 1 && isIdentifier(func.name)) { // TODO: Limitations of prototype + const methodType = getTypeOfPropertyOfType(basetypes[0], func.name.escapedText) + if (methodType) { + const sig = getSingleCallSignature(methodType) + if (sig) { + const i = func.parameters.indexOf(declaration) + if (i > -1) { + const t = tryGetTypeAtPosition(sig, i) + if (t) { // wtb nullable monad + return addOptionality(t, /*isProperty*/ false, isOptional); + } + } + } + } + } + } } // Use the type of the initializer expression if one is present and the declaration is diff --git a/tests/baselines/reference/quickInfoJsDocTags5.baseline b/tests/baselines/reference/quickInfoJsDocTags5.baseline index 167f3df49184f..4ea777d384402 100644 --- a/tests/baselines/reference/quickInfoJsDocTags5.baseline +++ b/tests/baselines/reference/quickInfoJsDocTags5.baseline @@ -58,7 +58,7 @@ "kind": "space" }, { - "text": "any", + "text": "number", "kind": "keyword" }, { @@ -82,7 +82,7 @@ "kind": "space" }, { - "text": "any", + "text": "number", "kind": "keyword" }, { diff --git a/tests/baselines/reference/quickInfoJsDocTags6.baseline b/tests/baselines/reference/quickInfoJsDocTags6.baseline index 7ab1d074034f5..9efe4dc932bba 100644 --- a/tests/baselines/reference/quickInfoJsDocTags6.baseline +++ b/tests/baselines/reference/quickInfoJsDocTags6.baseline @@ -58,7 +58,7 @@ "kind": "space" }, { - "text": "any", + "text": "number", "kind": "keyword" }, { @@ -82,7 +82,7 @@ "kind": "space" }, { - "text": "any", + "text": "number", "kind": "keyword" }, {