diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index ae19f8f41c7..4ce9d668412 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -19470,6 +19470,9 @@ namespace ts { case SyntaxKind.ConstructorType: checkUnusedTypeParameters(node); break; + case SyntaxKind.TypeAliasDeclaration: + checkUnusedTypeParameters(node); + break; } } } @@ -19547,7 +19550,7 @@ namespace ts { } } - function checkUnusedTypeParameters(node: ClassDeclaration | ClassExpression | FunctionDeclaration | MethodDeclaration | FunctionExpression | ArrowFunction | ConstructorDeclaration | SignatureDeclaration | InterfaceDeclaration) { + function checkUnusedTypeParameters(node: ClassDeclaration | ClassExpression | FunctionDeclaration | MethodDeclaration | FunctionExpression | ArrowFunction | ConstructorDeclaration | SignatureDeclaration | InterfaceDeclaration | TypeAliasDeclaration) { if (compilerOptions.noUnusedLocals && !isInAmbientContext(node)) { if (node.typeParameters) { // Only report errors on the last declaration for the type parameter container; @@ -21252,6 +21255,7 @@ namespace ts { checkTypeNameIsReserved(node.name, Diagnostics.Type_alias_name_cannot_be_0); checkTypeParameters(node.typeParameters); checkSourceElement(node.type); + registerForUnusedIdentifiersCheck(node); } function computeEnumMemberValues(node: EnumDeclaration) { diff --git a/tests/baselines/reference/unusedTypeParameters10.errors.txt b/tests/baselines/reference/unusedTypeParameters10.errors.txt new file mode 100644 index 00000000000..7bfd5676df3 --- /dev/null +++ b/tests/baselines/reference/unusedTypeParameters10.errors.txt @@ -0,0 +1,9 @@ +tests/cases/compiler/unusedTypeParameters10.ts(1,12): error TS6133: 'T' is declared but never used. + + +==== tests/cases/compiler/unusedTypeParameters10.ts (1 errors) ==== + type Alias = { }; + ~ +!!! error TS6133: 'T' is declared but never used. + type Alias2 = { x: T }; + \ No newline at end of file diff --git a/tests/baselines/reference/unusedTypeParameters10.js b/tests/baselines/reference/unusedTypeParameters10.js new file mode 100644 index 00000000000..5738e6f48e8 --- /dev/null +++ b/tests/baselines/reference/unusedTypeParameters10.js @@ -0,0 +1,6 @@ +//// [unusedTypeParameters10.ts] +type Alias = { }; +type Alias2 = { x: T }; + + +//// [unusedTypeParameters10.js] diff --git a/tests/cases/compiler/unusedTypeParameters10.ts b/tests/cases/compiler/unusedTypeParameters10.ts new file mode 100644 index 00000000000..cda482e5bdc --- /dev/null +++ b/tests/cases/compiler/unusedTypeParameters10.ts @@ -0,0 +1,5 @@ +//@noUnusedLocals:true +//@noUnusedParameters:true + +type Alias = { }; +type Alias2 = { x: T };