Skip to content

Commit 6281d1d

Browse files
authored
Merge pull request #12982 from Microsoft/jsdoc-instantiate-signature-with-function-arg
JSDoc functions are now in scope for instantiation
2 parents 330cced + 8ae9c7d commit 6281d1d

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

src/compiler/checker.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6645,7 +6645,7 @@ namespace ts {
66456645
// Starting with the parent of the symbol's declaration, check if the mapper maps any of
66466646
// the type parameters introduced by enclosing declarations. We just pick the first
66476647
// declaration since multiple declarations will all have the same parent anyway.
6648-
let node = symbol.declarations[0].parent;
6648+
let node: Node = symbol.declarations[0];
66496649
while (node) {
66506650
switch (node.kind) {
66516651
case SyntaxKind.FunctionType:
@@ -6665,7 +6665,7 @@ namespace ts {
66656665
case SyntaxKind.ClassExpression:
66666666
case SyntaxKind.InterfaceDeclaration:
66676667
case SyntaxKind.TypeAliasDeclaration:
6668-
const declaration = <DeclarationWithTypeParameters>node;
6668+
const declaration = node as DeclarationWithTypeParameters;
66696669
if (declaration.typeParameters) {
66706670
for (const d of declaration.typeParameters) {
66716671
if (contains(mappedTypes, getDeclaredTypeOfTypeParameter(getSymbolOfNode(d)))) {
@@ -6680,6 +6680,14 @@ namespace ts {
66806680
}
66816681
}
66826682
break;
6683+
case SyntaxKind.JSDocFunctionType:
6684+
const func = node as JSDocFunctionType;
6685+
for (const p of func.parameters) {
6686+
if (contains(mappedTypes, getTypeOfNode(p))) {
6687+
return true;
6688+
}
6689+
}
6690+
break;
66836691
case SyntaxKind.ModuleDeclaration:
66846692
case SyntaxKind.SourceFile:
66856693
return false;
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
///<reference path="fourslash.ts" />
2+
// @allowNonTsExtensions: true
3+
// @Filename: Foo.js
4+
5+
/////**
6+
//// * @param {T[]} arr
7+
//// * @param {(function(T):T)} valuator
8+
//// * @template T
9+
//// */
10+
////function SortFilter(arr,valuator)
11+
////{
12+
//// return arr;
13+
////}
14+
////var a/*1*/ = SortFilter([0, 1, 2], q/*2*/ => q);
15+
////var b/*3*/ = SortFilter([0, 1, 2], undefined);
16+
17+
verify.quickInfoAt('1', "var a: number[]");
18+
verify.quickInfoAt('2', '(parameter) q: number');
19+
verify.quickInfoAt('3', "var b: number[]");

0 commit comments

Comments
 (0)