Fix #9636: Report unused type paramters only on last declaration

This commit is contained in:
Mohamed Hegazy
2016-07-17 23:51:17 -07:00
parent 9ef65cf3af
commit 290caad402
16 changed files with 298 additions and 3 deletions

View File

@@ -13274,7 +13274,7 @@ namespace ts {
checkAsyncFunctionReturnType(<FunctionLikeDeclaration>node);
}
}
if (!(<FunctionDeclaration>node).body) {
if (noUnusedIdentifiers && !(<FunctionDeclaration>node).body) {
checkUnusedTypeParameters(node);
}
}
@@ -14609,8 +14609,15 @@ namespace ts {
function checkUnusedTypeParameters(node: ClassDeclaration | ClassExpression | FunctionDeclaration | MethodDeclaration | FunctionExpression | ArrowFunction | ConstructorDeclaration | SignatureDeclaration | InterfaceDeclaration) {
if (compilerOptions.noUnusedLocals && !isInAmbientContext(node)) {
if (node.typeParameters) {
// Only report errors on the last declaration for the type parameter container;
// this ensures that all uses have been accounted for.
const symbol = node.symbol && getMergedSymbol(node.symbol);
const lastDeclaration = symbol && symbol.declarations && lastOrUndefined(symbol.declarations);
if (lastDeclaration !== node) {
return;
}
for (const typeParameter of node.typeParameters) {
if (!typeParameter.symbol.isReferenced) {
if (!getMergedSymbol(typeParameter.symbol).isReferenced) {
error(typeParameter.name, Diagnostics._0_is_declared_but_never_used, typeParameter.symbol.name);
}
}
@@ -16119,7 +16126,7 @@ namespace ts {
if (produceDiagnostics) {
checkTypeForDuplicateIndexSignatures(node);
checkUnusedTypeParameters(node);
registerForUnusedIdentifiersCheck(node);
}
}