From ca324a0af5cea00b44ab63d396d8565c258772f0 Mon Sep 17 00:00:00 2001 From: magierjones Date: Mon, 9 Sep 2019 10:14:57 +0200 Subject: [PATCH] fix #32843 : evaluate right scope when checked if all type parameter are unused for jsdoc `@template` --- src/compiler/checker.ts | 2 +- ...usedTypeParameters_templateTag2.errors.txt | 42 +++++++++++++++++++ .../unusedTypeParameters_templateTag2.symbols | 40 ++++++++++++++++++ .../unusedTypeParameters_templateTag2.types | 40 ++++++++++++++++++ .../unusedTypeParameters_templateTag2.ts | 34 +++++++++++++++ 5 files changed, 157 insertions(+), 1 deletion(-) create mode 100644 tests/baselines/reference/unusedTypeParameters_templateTag2.errors.txt create mode 100644 tests/baselines/reference/unusedTypeParameters_templateTag2.symbols create mode 100644 tests/baselines/reference/unusedTypeParameters_templateTag2.types create mode 100644 tests/cases/compiler/unusedTypeParameters_templateTag2.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 758b6252ea957..69b5d62a0e627 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -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)); diff --git a/tests/baselines/reference/unusedTypeParameters_templateTag2.errors.txt b/tests/baselines/reference/unusedTypeParameters_templateTag2.errors.txt new file mode 100644 index 0000000000000..40da52ffbd7ea --- /dev/null +++ b/tests/baselines/reference/unusedTypeParameters_templateTag2.errors.txt @@ -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; + } + } \ No newline at end of file diff --git a/tests/baselines/reference/unusedTypeParameters_templateTag2.symbols b/tests/baselines/reference/unusedTypeParameters_templateTag2.symbols new file mode 100644 index 0000000000000..c38b52a9bbdfa --- /dev/null +++ b/tests/baselines/reference/unusedTypeParameters_templateTag2.symbols @@ -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)) + } +} diff --git a/tests/baselines/reference/unusedTypeParameters_templateTag2.types b/tests/baselines/reference/unusedTypeParameters_templateTag2.types new file mode 100644 index 0000000000000..45e33a5e3799e --- /dev/null +++ b/tests/baselines/reference/unusedTypeParameters_templateTag2.types @@ -0,0 +1,40 @@ +=== /a.js === +/** + * @template T + * @template V + */ +class C1 { +>C1 : C1 + + constructor() { + /** @type {T} */ + this.p; +>this.p : T +>this : this +>p : T + } +} + +/** + * @template T,V + */ +class C2 { +>C2 : C2 + + constructor() { } +} + +/** + * @template T,V,X + */ +class C3 { +>C3 : C3 + + constructor() { + /** @type {T} */ + this.p; +>this.p : T +>this : this +>p : T + } +} diff --git a/tests/cases/compiler/unusedTypeParameters_templateTag2.ts b/tests/cases/compiler/unusedTypeParameters_templateTag2.ts new file mode 100644 index 0000000000000..5db7a82a89804 --- /dev/null +++ b/tests/cases/compiler/unusedTypeParameters_templateTag2.ts @@ -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; + } +} \ No newline at end of file