Skip to content

Commit c51c2ae

Browse files
authored
Merge pull request #16736 from DickvdBrink/issue/15208
Also check TypeAlias for unused type parameters
2 parents cf0fe92 + 3322474 commit c51c2ae

File tree

4 files changed

+25
-1
lines changed

4 files changed

+25
-1
lines changed

src/compiler/checker.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19470,6 +19470,9 @@ namespace ts {
1947019470
case SyntaxKind.ConstructorType:
1947119471
checkUnusedTypeParameters(<FunctionLikeDeclaration>node);
1947219472
break;
19473+
case SyntaxKind.TypeAliasDeclaration:
19474+
checkUnusedTypeParameters(<TypeAliasDeclaration>node);
19475+
break;
1947319476
}
1947419477
}
1947519478
}
@@ -19547,7 +19550,7 @@ namespace ts {
1954719550
}
1954819551
}
1954919552

19550-
function checkUnusedTypeParameters(node: ClassDeclaration | ClassExpression | FunctionDeclaration | MethodDeclaration | FunctionExpression | ArrowFunction | ConstructorDeclaration | SignatureDeclaration | InterfaceDeclaration) {
19553+
function checkUnusedTypeParameters(node: ClassDeclaration | ClassExpression | FunctionDeclaration | MethodDeclaration | FunctionExpression | ArrowFunction | ConstructorDeclaration | SignatureDeclaration | InterfaceDeclaration | TypeAliasDeclaration) {
1955119554
if (compilerOptions.noUnusedLocals && !isInAmbientContext(node)) {
1955219555
if (node.typeParameters) {
1955319556
// Only report errors on the last declaration for the type parameter container;
@@ -21252,6 +21255,7 @@ namespace ts {
2125221255
checkTypeNameIsReserved(node.name, Diagnostics.Type_alias_name_cannot_be_0);
2125321256
checkTypeParameters(node.typeParameters);
2125421257
checkSourceElement(node.type);
21258+
registerForUnusedIdentifiersCheck(node);
2125521259
}
2125621260

2125721261
function computeEnumMemberValues(node: EnumDeclaration) {
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
tests/cases/compiler/unusedTypeParameters10.ts(1,12): error TS6133: 'T' is declared but never used.
2+
3+
4+
==== tests/cases/compiler/unusedTypeParameters10.ts (1 errors) ====
5+
type Alias<T> = { };
6+
~
7+
!!! error TS6133: 'T' is declared but never used.
8+
type Alias2<T> = { x: T };
9+
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
//// [unusedTypeParameters10.ts]
2+
type Alias<T> = { };
3+
type Alias2<T> = { x: T };
4+
5+
6+
//// [unusedTypeParameters10.js]
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
//@noUnusedLocals:true
2+
//@noUnusedParameters:true
3+
4+
type Alias<T> = { };
5+
type Alias2<T> = { x: T };

0 commit comments

Comments
 (0)