Skip to content

Commit 8ae9c7d

Browse files
committed
JSDoc functions are now in scope for instantiation
Previously, `isSymbolInScopeOfMappedTypeParameter` did not understand JSDoc, so it would cause generic function declarations in JSDoc not be instantiated.
1 parent 757af49 commit 8ae9c7d

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
@@ -6634,7 +6634,7 @@ namespace ts {
66346634
// Starting with the parent of the symbol's declaration, check if the mapper maps any of
66356635
// the type parameters introduced by enclosing declarations. We just pick the first
66366636
// declaration since multiple declarations will all have the same parent anyway.
6637-
let node = symbol.declarations[0].parent;
6637+
let node: Node = symbol.declarations[0];
66386638
while (node) {
66396639
switch (node.kind) {
66406640
case SyntaxKind.FunctionType:
@@ -6654,7 +6654,7 @@ namespace ts {
66546654
case SyntaxKind.ClassExpression:
66556655
case SyntaxKind.InterfaceDeclaration:
66566656
case SyntaxKind.TypeAliasDeclaration:
6657-
const declaration = <DeclarationWithTypeParameters>node;
6657+
const declaration = node as DeclarationWithTypeParameters;
66586658
if (declaration.typeParameters) {
66596659
for (const d of declaration.typeParameters) {
66606660
if (contains(mappedTypes, getDeclaredTypeOfTypeParameter(getSymbolOfNode(d)))) {
@@ -6669,6 +6669,14 @@ namespace ts {
66696669
}
66706670
}
66716671
break;
6672+
case SyntaxKind.JSDocFunctionType:
6673+
const func = node as JSDocFunctionType;
6674+
for (const p of func.parameters) {
6675+
if (contains(mappedTypes, getTypeOfNode(p))) {
6676+
return true;
6677+
}
6678+
}
6679+
break;
66726680
case SyntaxKind.ModuleDeclaration:
66736681
case SyntaxKind.SourceFile:
66746682
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)