Fix getSignatureOfTypeTag (#37473)

Prevents infinite looping as in #37265.

Fixes #37265
This commit is contained in:
Eli Barzilay
2020-03-19 19:02:39 -04:00
committed by GitHub
parent 292d01880f
commit ec95c27b4d
5 changed files with 64 additions and 1 deletions

View File

@@ -10701,7 +10701,9 @@ namespace ts {
}
function getSignatureOfTypeTag(node: SignatureDeclaration | JSDocSignature) {
const typeTag = isInJSFile(node) ? getJSDocTypeTag(node) : undefined;
// should be attached to a function declaration or expression
if (!(isInJSFile(node) && isFunctionLikeDeclaration(node))) return undefined;
const typeTag = getJSDocTypeTag(node);
const signature = typeTag && typeTag.typeExpression && getSingleCallSignature(getTypeFromTypeNode(typeTag.typeExpression));
return signature && getErasedSignature(signature);
}

View File

@@ -0,0 +1,15 @@
/a.js(8,3): error TS2554: Expected 0 arguments, but got 1.
==== /a.js (1 errors) ====
/**
* @template T
* @callback B
*/
/** @type {B<string>} */
let b;
b();
b(1);
~
!!! error TS2554: Expected 0 arguments, but got 1.

View File

@@ -0,0 +1,15 @@
=== /a.js ===
/**
* @template T
* @callback B
*/
/** @type {B<string>} */
let b;
>b : Symbol(b, Decl(a.js, 5, 3))
b();
>b : Symbol(b, Decl(a.js, 5, 3))
b(1);
>b : Symbol(b, Decl(a.js, 5, 3))

View File

@@ -0,0 +1,18 @@
=== /a.js ===
/**
* @template T
* @callback B
*/
/** @type {B<string>} */
let b;
>b : B<string>
b();
>b() : any
>b : B<string>
b(1);
>b(1) : any
>b : B<string>
>1 : 1

View File

@@ -0,0 +1,13 @@
// @allowJs: true
// @checkJs: true
// @noEmit: true
// @Filename: /a.js
/**
* @template T
* @callback B
*/
/** @type {B<string>} */
let b;
b();
b(1);