From 14a457e51857c8a668560b430d5d923c0b25eb2d Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Fri, 19 Feb 2016 13:05:19 -0800 Subject: [PATCH] Address review comments 1. Give class name in error message. 2. Reduce nesting via an early exit. --- src/compiler/checker.ts | 19 ++++++++++--------- src/compiler/diagnosticMessages.json | 2 +- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index b9a8ab6cd2c..dbce5f41ef4 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -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 = 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 = declaration; + } + else if (!areTypeParametersIdentical(firstDecl.typeParameters, node.typeParameters)) { + error(node.name, Diagnostics.All_declarations_of_0_must_have_identical_type_parameters, node.name.text); } } } diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 92396d005b7..70c6d8ff167 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -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 },