Skip to content

Commit ec95c27

Browse files
authored
Fix getSignatureOfTypeTag (#37473)
Prevents infinite looping as in #37265. Fixes #37265
1 parent 292d018 commit ec95c27

File tree

5 files changed

+64
-1
lines changed

5 files changed

+64
-1
lines changed

src/compiler/checker.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10701,7 +10701,9 @@ namespace ts {
1070110701
}
1070210702

1070310703
function getSignatureOfTypeTag(node: SignatureDeclaration | JSDocSignature) {
10704-
const typeTag = isInJSFile(node) ? getJSDocTypeTag(node) : undefined;
10704+
// should be attached to a function declaration or expression
10705+
if (!(isInJSFile(node) && isFunctionLikeDeclaration(node))) return undefined;
10706+
const typeTag = getJSDocTypeTag(node);
1070510707
const signature = typeTag && typeTag.typeExpression && getSingleCallSignature(getTypeFromTypeNode(typeTag.typeExpression));
1070610708
return signature && getErasedSignature(signature);
1070710709
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/a.js(8,3): error TS2554: Expected 0 arguments, but got 1.
2+
3+
4+
==== /a.js (1 errors) ====
5+
/**
6+
* @template T
7+
* @callback B
8+
*/
9+
/** @type {B<string>} */
10+
let b;
11+
b();
12+
b(1);
13+
~
14+
!!! error TS2554: Expected 0 arguments, but got 1.
15+
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
=== /a.js ===
2+
/**
3+
* @template T
4+
* @callback B
5+
*/
6+
/** @type {B<string>} */
7+
let b;
8+
>b : Symbol(b, Decl(a.js, 5, 3))
9+
10+
b();
11+
>b : Symbol(b, Decl(a.js, 5, 3))
12+
13+
b(1);
14+
>b : Symbol(b, Decl(a.js, 5, 3))
15+
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
=== /a.js ===
2+
/**
3+
* @template T
4+
* @callback B
5+
*/
6+
/** @type {B<string>} */
7+
let b;
8+
>b : B<string>
9+
10+
b();
11+
>b() : any
12+
>b : B<string>
13+
14+
b(1);
15+
>b(1) : any
16+
>b : B<string>
17+
>1 : 1
18+
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// @allowJs: true
2+
// @checkJs: true
3+
// @noEmit: true
4+
5+
// @Filename: /a.js
6+
/**
7+
* @template T
8+
* @callback B
9+
*/
10+
/** @type {B<string>} */
11+
let b;
12+
b();
13+
b(1);

0 commit comments

Comments
 (0)