Address review comments

1. Give class name in error message.
2. Reduce nesting via an early exit.
This commit is contained in:
Nathan Shively-Sanders 2016-02-19 13:05:19 -08:00
parent 0d3f6473cf
commit 14a457e518
2 changed files with 11 additions and 10 deletions

View File

@ -14033,16 +14033,17 @@ namespace ts {
/** Check that type parameter lists are identical across multiple declarations */
function checkTypeParameterListsIdentical(node: ClassLikeDeclaration | InterfaceDeclaration, symbol: Symbol) {
if (symbol.declarations.length === 1) {
return;
}
let firstDecl: ClassLikeDeclaration | InterfaceDeclaration;
if (symbol.declarations.length > 1) {
for (const declaration of symbol.declarations) {
if (declaration.kind === SyntaxKind.ClassDeclaration || declaration.kind === SyntaxKind.InterfaceDeclaration) {
if (!firstDecl) {
firstDecl = <ClassLikeDeclaration | InterfaceDeclaration>declaration;
}
else if (!areTypeParametersIdentical(firstDecl.typeParameters, node.typeParameters)) {
error(node.name, Diagnostics.All_declarations_must_have_identical_type_parameters);
}
for (const declaration of symbol.declarations) {
if (declaration.kind === SyntaxKind.ClassDeclaration || declaration.kind === SyntaxKind.InterfaceDeclaration) {
if (!firstDecl) {
firstDecl = <ClassLikeDeclaration | InterfaceDeclaration>declaration;
}
else if (!areTypeParametersIdentical(firstDecl.typeParameters, node.typeParameters)) {
error(node.name, Diagnostics.All_declarations_of_0_must_have_identical_type_parameters, node.name.text);
}
}
}

View File

@ -1311,7 +1311,7 @@
"category": "Error",
"code": 2427
},
"All declarations must have identical type parameters.": {
"All declarations of '{0}' must have identical type parameters.": {
"category": "Error",
"code": 2428
},