mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-23 10:29:01 -06:00
Fix error message for class type in JSDoc missing type arguments (#27222)
This commit is contained in:
parent
80045ca2d8
commit
67d8263b30
@ -8158,7 +8158,7 @@ namespace ts {
|
||||
const isJs = isInJSFile(node);
|
||||
const isJsImplicitAny = !noImplicitAny && isJs;
|
||||
if (!isJsImplicitAny && (numTypeArguments < minTypeArgumentCount || numTypeArguments > typeParameters.length)) {
|
||||
const missingAugmentsTag = isJs && node.parent.kind !== SyntaxKind.JSDocAugmentsTag;
|
||||
const missingAugmentsTag = isJs && isExpressionWithTypeArguments(node) && !isJSDocAugmentsTag(node.parent);
|
||||
const diag = minTypeArgumentCount === typeParameters.length
|
||||
? missingAugmentsTag
|
||||
? Diagnostics.Expected_0_type_arguments_provide_these_with_an_extends_tag
|
||||
|
||||
@ -0,0 +1,12 @@
|
||||
/a.js(4,13): error TS2314: Generic type 'C<T>' requires 1 type argument(s).
|
||||
|
||||
|
||||
==== /a.js (1 errors) ====
|
||||
/** @template T */
|
||||
class C {}
|
||||
|
||||
/** @param {C} p */
|
||||
~
|
||||
!!! error TS2314: Generic type 'C<T>' requires 1 type argument(s).
|
||||
function f(p) {}
|
||||
|
||||
@ -0,0 +1,10 @@
|
||||
=== /a.js ===
|
||||
/** @template T */
|
||||
class C {}
|
||||
>C : Symbol(C, Decl(a.js, 0, 0))
|
||||
|
||||
/** @param {C} p */
|
||||
function f(p) {}
|
||||
>f : Symbol(f, Decl(a.js, 1, 10))
|
||||
>p : Symbol(p, Decl(a.js, 4, 11))
|
||||
|
||||
@ -0,0 +1,10 @@
|
||||
=== /a.js ===
|
||||
/** @template T */
|
||||
class C {}
|
||||
>C : C<T>
|
||||
|
||||
/** @param {C} p */
|
||||
function f(p) {}
|
||||
>f : (p: C<any>) => void
|
||||
>p : C<any>
|
||||
|
||||
11
tests/cases/compiler/jsdocClassMissingTypeArguments.ts
Normal file
11
tests/cases/compiler/jsdocClassMissingTypeArguments.ts
Normal file
@ -0,0 +1,11 @@
|
||||
// @allowJs: true
|
||||
// @checkJs: true
|
||||
// @noEmit: true
|
||||
// @noImplicitAny: true
|
||||
|
||||
// @Filename: /a.js
|
||||
/** @template T */
|
||||
class C {}
|
||||
|
||||
/** @param {C} p */
|
||||
function f(p) {}
|
||||
Loading…
x
Reference in New Issue
Block a user