Skip to content

Commit 67d8263

Browse files
author
Andy
authored
Fix error message for class type in JSDoc missing type arguments (#27222)
1 parent 80045ca commit 67d8263

File tree

5 files changed

+44
-1
lines changed

5 files changed

+44
-1
lines changed

src/compiler/checker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8158,7 +8158,7 @@ namespace ts {
81588158
const isJs = isInJSFile(node);
81598159
const isJsImplicitAny = !noImplicitAny && isJs;
81608160
if (!isJsImplicitAny && (numTypeArguments < minTypeArgumentCount || numTypeArguments > typeParameters.length)) {
8161-
const missingAugmentsTag = isJs && node.parent.kind !== SyntaxKind.JSDocAugmentsTag;
8161+
const missingAugmentsTag = isJs && isExpressionWithTypeArguments(node) && !isJSDocAugmentsTag(node.parent);
81628162
const diag = minTypeArgumentCount === typeParameters.length
81638163
? missingAugmentsTag
81648164
? Diagnostics.Expected_0_type_arguments_provide_these_with_an_extends_tag
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/a.js(4,13): error TS2314: Generic type 'C<T>' requires 1 type argument(s).
2+
3+
4+
==== /a.js (1 errors) ====
5+
/** @template T */
6+
class C {}
7+
8+
/** @param {C} p */
9+
~
10+
!!! error TS2314: Generic type 'C<T>' requires 1 type argument(s).
11+
function f(p) {}
12+
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
=== /a.js ===
2+
/** @template T */
3+
class C {}
4+
>C : Symbol(C, Decl(a.js, 0, 0))
5+
6+
/** @param {C} p */
7+
function f(p) {}
8+
>f : Symbol(f, Decl(a.js, 1, 10))
9+
>p : Symbol(p, Decl(a.js, 4, 11))
10+
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
=== /a.js ===
2+
/** @template T */
3+
class C {}
4+
>C : C<T>
5+
6+
/** @param {C} p */
7+
function f(p) {}
8+
>f : (p: C<any>) => void
9+
>p : C<any>
10+
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// @allowJs: true
2+
// @checkJs: true
3+
// @noEmit: true
4+
// @noImplicitAny: true
5+
6+
// @Filename: /a.js
7+
/** @template T */
8+
class C {}
9+
10+
/** @param {C} p */
11+
function f(p) {}

0 commit comments

Comments
 (0)