Skip to content

fix #32843 : evaluate right scope when checked if all type parameter … #33320

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 31, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27386,7 +27386,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));
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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))
}
}
40 changes: 40 additions & 0 deletions tests/baselines/reference/unusedTypeParameters_templateTag2.types
Original file line number Diff line number Diff line change
@@ -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 changes: 34 additions & 0 deletions tests/cases/compiler/unusedTypeParameters_templateTag2.ts
Original file line number Diff line number Diff line change
@@ -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;
}
}