mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-06-10 18:04:18 -05:00
fix #32843 : evaluate right scope when checked if all type parameter are unused for jsdoc @template (#33320)
Co-authored-by: magierjones <simon.jaeger@magierjones.de>
This commit is contained in:
@@ -30990,7 +30990,7 @@ namespace ts {
|
||||
? rangeOfNode(parent)
|
||||
// Include the `<>` in the error message
|
||||
: rangeOfTypeParameters(parent.typeParameters!);
|
||||
const only = typeParameters.length === 1;
|
||||
const only = parent.typeParameters!.length === 1;
|
||||
const message = only ? Diagnostics._0_is_declared_but_its_value_is_never_read : Diagnostics.All_type_parameters_are_unused;
|
||||
const arg0 = only ? name : undefined;
|
||||
addDiagnostic(typeParameter, UnusedKind.Parameter, createFileDiagnostic(getSourceFileOfNode(parent), range.pos, range.end - range.pos, message, arg0));
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
/a.js(3,4): error TS6133: 'V' is declared but its value is never read.
|
||||
/a.js(13,4): error TS6205: All type parameters are unused
|
||||
/a.js(20,16): error TS6133: 'V' is declared but its value is never read.
|
||||
/a.js(20,18): error TS6133: 'X' is declared but its value is never read.
|
||||
|
||||
|
||||
==== /a.js (4 errors) ====
|
||||
/**
|
||||
* @template T
|
||||
* @template V
|
||||
~~~~~~~~~~~
|
||||
!!! error TS6133: 'V' is declared but its value is never read.
|
||||
*/
|
||||
class C1 {
|
||||
constructor() {
|
||||
/** @type {T} */
|
||||
this.p;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @template T,V
|
||||
~~~~~~~~~~~~~
|
||||
!!! error TS6205: All type parameters are unused
|
||||
*/
|
||||
class C2 {
|
||||
constructor() { }
|
||||
}
|
||||
|
||||
/**
|
||||
* @template T,V,X
|
||||
~
|
||||
!!! error TS6133: 'V' is declared but its value is never read.
|
||||
~
|
||||
!!! error TS6133: 'X' is declared but its value is never read.
|
||||
*/
|
||||
class C3 {
|
||||
constructor() {
|
||||
/** @type {T} */
|
||||
this.p;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
=== /a.js ===
|
||||
/**
|
||||
* @template T
|
||||
* @template V
|
||||
*/
|
||||
class C1 {
|
||||
>C1 : Symbol(C1, Decl(a.js, 0, 0))
|
||||
|
||||
constructor() {
|
||||
/** @type {T} */
|
||||
this.p;
|
||||
>this.p : Symbol(C1.p, Decl(a.js, 5, 19))
|
||||
>this : Symbol(C1, Decl(a.js, 0, 0))
|
||||
>p : Symbol(C1.p, Decl(a.js, 5, 19))
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @template T,V
|
||||
*/
|
||||
class C2 {
|
||||
>C2 : Symbol(C2, Decl(a.js, 9, 1))
|
||||
|
||||
constructor() { }
|
||||
}
|
||||
|
||||
/**
|
||||
* @template T,V,X
|
||||
*/
|
||||
class C3 {
|
||||
>C3 : Symbol(C3, Decl(a.js, 16, 1))
|
||||
|
||||
constructor() {
|
||||
/** @type {T} */
|
||||
this.p;
|
||||
>this.p : Symbol(C3.p, Decl(a.js, 22, 19))
|
||||
>this : Symbol(C3, Decl(a.js, 16, 1))
|
||||
>p : Symbol(C3.p, Decl(a.js, 22, 19))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
=== /a.js ===
|
||||
/**
|
||||
* @template T
|
||||
* @template V
|
||||
*/
|
||||
class C1 {
|
||||
>C1 : C1<T, V>
|
||||
|
||||
constructor() {
|
||||
/** @type {T} */
|
||||
this.p;
|
||||
>this.p : T
|
||||
>this : this
|
||||
>p : T
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @template T,V
|
||||
*/
|
||||
class C2 {
|
||||
>C2 : C2<T, V>
|
||||
|
||||
constructor() { }
|
||||
}
|
||||
|
||||
/**
|
||||
* @template T,V,X
|
||||
*/
|
||||
class C3 {
|
||||
>C3 : C3<T, V, X>
|
||||
|
||||
constructor() {
|
||||
/** @type {T} */
|
||||
this.p;
|
||||
>this.p : T
|
||||
>this : this
|
||||
>p : T
|
||||
}
|
||||
}
|
||||
34
tests/cases/compiler/unusedTypeParameters_templateTag2.ts
Normal file
34
tests/cases/compiler/unusedTypeParameters_templateTag2.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
// @allowJs: true
|
||||
// @checkJs: true
|
||||
// @noEmit: true
|
||||
// @noUnusedParameters:true
|
||||
|
||||
// @Filename: /a.js
|
||||
|
||||
/**
|
||||
* @template T
|
||||
* @template V
|
||||
*/
|
||||
class C1 {
|
||||
constructor() {
|
||||
/** @type {T} */
|
||||
this.p;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @template T,V
|
||||
*/
|
||||
class C2 {
|
||||
constructor() { }
|
||||
}
|
||||
|
||||
/**
|
||||
* @template T,V,X
|
||||
*/
|
||||
class C3 {
|
||||
constructor() {
|
||||
/** @type {T} */
|
||||
this.p;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user