Merge pull request #16736 from DickvdBrink/issue/15208

Also check TypeAlias for unused type parameters
This commit is contained in:
Nathan Shively-Sanders 2017-06-28 12:37:04 -07:00 committed by GitHub
commit c51c2aecca
4 changed files with 25 additions and 1 deletions

View File

@ -19470,6 +19470,9 @@ namespace ts {
case SyntaxKind.ConstructorType:
checkUnusedTypeParameters(<FunctionLikeDeclaration>node);
break;
case SyntaxKind.TypeAliasDeclaration:
checkUnusedTypeParameters(<TypeAliasDeclaration>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) {

View File

@ -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<T> = { };
~
!!! error TS6133: 'T' is declared but never used.
type Alias2<T> = { x: T };

View File

@ -0,0 +1,6 @@
//// [unusedTypeParameters10.ts]
type Alias<T> = { };
type Alias2<T> = { x: T };
//// [unusedTypeParameters10.js]

View File

@ -0,0 +1,5 @@
//@noUnusedLocals:true
//@noUnusedParameters:true
type Alias<T> = { };
type Alias2<T> = { x: T };