Skip to content

Commit 9c4cbd6

Browse files
Simon Jaegermagierjones
Simon Jaeger
and
magierjones
authored
fix microsoft#32843 : evaluate right scope when checked if all type parameter are unused for jsdoc @template (microsoft#33320)
Co-authored-by: magierjones <[email protected]>
1 parent 4dc827e commit 9c4cbd6

5 files changed

+157
-1
lines changed

src/compiler/checker.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -30990,7 +30990,7 @@ namespace ts {
3099030990
? rangeOfNode(parent)
3099130991
// Include the `<>` in the error message
3099230992
: rangeOfTypeParameters(parent.typeParameters!);
30993-
const only = typeParameters.length === 1;
30993+
const only = parent.typeParameters!.length === 1;
3099430994
const message = only ? Diagnostics._0_is_declared_but_its_value_is_never_read : Diagnostics.All_type_parameters_are_unused;
3099530995
const arg0 = only ? name : undefined;
3099630996
addDiagnostic(typeParameter, UnusedKind.Parameter, createFileDiagnostic(getSourceFileOfNode(parent), range.pos, range.end - range.pos, message, arg0));
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/a.js(3,4): error TS6133: 'V' is declared but its value is never read.
2+
/a.js(13,4): error TS6205: All type parameters are unused
3+
/a.js(20,16): error TS6133: 'V' is declared but its value is never read.
4+
/a.js(20,18): error TS6133: 'X' is declared but its value is never read.
5+
6+
7+
==== /a.js (4 errors) ====
8+
/**
9+
* @template T
10+
* @template V
11+
~~~~~~~~~~~
12+
!!! error TS6133: 'V' is declared but its value is never read.
13+
*/
14+
class C1 {
15+
constructor() {
16+
/** @type {T} */
17+
this.p;
18+
}
19+
}
20+
21+
/**
22+
* @template T,V
23+
~~~~~~~~~~~~~
24+
!!! error TS6205: All type parameters are unused
25+
*/
26+
class C2 {
27+
constructor() { }
28+
}
29+
30+
/**
31+
* @template T,V,X
32+
~
33+
!!! error TS6133: 'V' is declared but its value is never read.
34+
~
35+
!!! error TS6133: 'X' is declared but its value is never read.
36+
*/
37+
class C3 {
38+
constructor() {
39+
/** @type {T} */
40+
this.p;
41+
}
42+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
=== /a.js ===
2+
/**
3+
* @template T
4+
* @template V
5+
*/
6+
class C1 {
7+
>C1 : Symbol(C1, Decl(a.js, 0, 0))
8+
9+
constructor() {
10+
/** @type {T} */
11+
this.p;
12+
>this.p : Symbol(C1.p, Decl(a.js, 5, 19))
13+
>this : Symbol(C1, Decl(a.js, 0, 0))
14+
>p : Symbol(C1.p, Decl(a.js, 5, 19))
15+
}
16+
}
17+
18+
/**
19+
* @template T,V
20+
*/
21+
class C2 {
22+
>C2 : Symbol(C2, Decl(a.js, 9, 1))
23+
24+
constructor() { }
25+
}
26+
27+
/**
28+
* @template T,V,X
29+
*/
30+
class C3 {
31+
>C3 : Symbol(C3, Decl(a.js, 16, 1))
32+
33+
constructor() {
34+
/** @type {T} */
35+
this.p;
36+
>this.p : Symbol(C3.p, Decl(a.js, 22, 19))
37+
>this : Symbol(C3, Decl(a.js, 16, 1))
38+
>p : Symbol(C3.p, Decl(a.js, 22, 19))
39+
}
40+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
=== /a.js ===
2+
/**
3+
* @template T
4+
* @template V
5+
*/
6+
class C1 {
7+
>C1 : C1<T, V>
8+
9+
constructor() {
10+
/** @type {T} */
11+
this.p;
12+
>this.p : T
13+
>this : this
14+
>p : T
15+
}
16+
}
17+
18+
/**
19+
* @template T,V
20+
*/
21+
class C2 {
22+
>C2 : C2<T, V>
23+
24+
constructor() { }
25+
}
26+
27+
/**
28+
* @template T,V,X
29+
*/
30+
class C3 {
31+
>C3 : C3<T, V, X>
32+
33+
constructor() {
34+
/** @type {T} */
35+
this.p;
36+
>this.p : T
37+
>this : this
38+
>p : T
39+
}
40+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// @allowJs: true
2+
// @checkJs: true
3+
// @noEmit: true
4+
// @noUnusedParameters:true
5+
6+
// @Filename: /a.js
7+
8+
/**
9+
* @template T
10+
* @template V
11+
*/
12+
class C1 {
13+
constructor() {
14+
/** @type {T} */
15+
this.p;
16+
}
17+
}
18+
19+
/**
20+
* @template T,V
21+
*/
22+
class C2 {
23+
constructor() { }
24+
}
25+
26+
/**
27+
* @template T,V,X
28+
*/
29+
class C3 {
30+
constructor() {
31+
/** @type {T} */
32+
this.p;
33+
}
34+
}

0 commit comments

Comments
 (0)