Remove location of other declaration from "Subsequent x declarations must have same type" errors (#20206)

This commit is contained in:
Andy
2017-11-29 10:54:13 -05:00
committed by GitHub
parent b6f53eb5a9
commit 618b6702f0
65 changed files with 294 additions and 299 deletions

View File

@@ -4479,7 +4479,7 @@ namespace ts {
jsDocType = declarationType;
}
else if (jsDocType !== unknownType && declarationType !== unknownType && !isTypeIdenticalTo(jsDocType, declarationType)) {
errorNextVariableOrPropertyDeclarationMustHaveSameType(symbol.valueDeclaration, jsDocType, declaration, declarationType);
errorNextVariableOrPropertyDeclarationMustHaveSameType(jsDocType, declaration, declarationType);
}
}
else if (!jsDocType) {
@@ -21441,7 +21441,7 @@ namespace ts {
// initializer is consistent with type associated with the node
const declarationType = convertAutoToAny(getWidenedTypeForVariableLikeDeclaration(node));
if (type !== unknownType && declarationType !== unknownType && !isTypeIdenticalTo(type, declarationType)) {
errorNextVariableOrPropertyDeclarationMustHaveSameType(symbol.valueDeclaration, type, node, declarationType);
errorNextVariableOrPropertyDeclarationMustHaveSameType(type, node, declarationType);
}
if (node.initializer) {
checkTypeAssignableTo(checkExpressionCached(node.initializer), declarationType, node, /*headMessage*/ undefined);
@@ -21465,21 +21465,16 @@ namespace ts {
}
}
function errorNextVariableOrPropertyDeclarationMustHaveSameType(firstDeclaration: Declaration, firstType: Type, nextDeclaration: Declaration, nextType: Type): void {
const firstSourceFile = getSourceFileOfNode(firstDeclaration);
const firstSpan = getErrorSpanForNode(firstSourceFile, getNameOfDeclaration(firstDeclaration) || firstDeclaration);
const firstLocation = getLineAndCharacterOfPosition(firstSourceFile, firstSpan.start);
const firstLocationDescription = firstSourceFile.fileName + " " + firstLocation.line + ":" + firstLocation.character;
function errorNextVariableOrPropertyDeclarationMustHaveSameType(firstType: Type, nextDeclaration: Declaration, nextType: Type): void {
const nextDeclarationName = getNameOfDeclaration(nextDeclaration);
const message = nextDeclaration.kind === SyntaxKind.PropertyDeclaration || nextDeclaration.kind === SyntaxKind.PropertySignature
? Diagnostics.Subsequent_property_declarations_must_have_the_same_type_Property_0_has_type_1_at_2_but_here_has_type_3
: Diagnostics.Subsequent_variable_declarations_must_have_the_same_type_Variable_0_has_type_1_at_2_but_here_has_type_3;
? Diagnostics.Subsequent_property_declarations_must_have_the_same_type_Property_0_must_be_of_type_1_but_here_has_type_2
: Diagnostics.Subsequent_variable_declarations_must_have_the_same_type_Variable_0_must_be_of_type_1_but_here_has_type_2;
error(
nextDeclarationName,
message,
declarationNameToString(nextDeclarationName),
typeToString(firstType),
firstLocationDescription,
typeToString(nextType));
}

View File

@@ -1344,7 +1344,7 @@
"category": "Error",
"code": 2402
},
"Subsequent variable declarations must have the same type. Variable '{0}' has type '{1}' at {2}, but here has type '{3}'.": {
"Subsequent variable declarations must have the same type. Variable '{0}' must be of type '{1}', but here has type '{2}'.": {
"category": "Error",
"code": 2403
},
@@ -2264,7 +2264,7 @@
"category": "Error",
"code": 2716
},
"Subsequent property declarations must have the same type. Property '{0}' has type '{1}' at {2}, but here has type '{3}'.": {
"Subsequent property declarations must have the same type. Property '{0}' must be of type '{1}', but here has type '{2}'.": {
"category": "Error",
"code": 2717
},
@@ -2606,7 +2606,7 @@
"category": "Error",
"code": 4102
},
"The current host does not support the '{0}' option.": {
"category": "Error",
"code": 5001