Skip to content

Commit 3f59129

Browse files
Add related span to original declaration on disagreeing variable/property types.
1 parent c71423e commit 3f59129

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

src/compiler/checker.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5352,7 +5352,7 @@ namespace ts {
53525352
return type;
53535353
}
53545354
else if (declaredType !== errorType && type !== errorType && !isTypeIdenticalTo(declaredType, type)) {
5355-
errorNextVariableOrPropertyDeclarationMustHaveSameType(declaredType, declaration, type);
5355+
errorNextVariableOrPropertyDeclarationMustHaveSameType(/*firstDeclaration*/ undefined, declaredType, declaration, type);
53565356
}
53575357
}
53585358
return declaredType;
@@ -26839,7 +26839,7 @@ namespace ts {
2683926839
if (type !== errorType && declarationType !== errorType &&
2684026840
!isTypeIdenticalTo(type, declarationType) &&
2684126841
!(symbol.flags & SymbolFlags.Assignment)) {
26842-
errorNextVariableOrPropertyDeclarationMustHaveSameType(type, node, declarationType);
26842+
errorNextVariableOrPropertyDeclarationMustHaveSameType(symbol.valueDeclaration, type, node, declarationType);
2684326843
}
2684426844
if (node.initializer) {
2684526845
checkTypeAssignableToAndOptionallyElaborate(checkExpressionCached(node.initializer), declarationType, node, node.initializer, /*headMessage*/ undefined);
@@ -26859,17 +26859,24 @@ namespace ts {
2685926859
}
2686026860
}
2686126861

26862-
function errorNextVariableOrPropertyDeclarationMustHaveSameType(firstType: Type, nextDeclaration: Declaration, nextType: Type): void {
26862+
function errorNextVariableOrPropertyDeclarationMustHaveSameType(firstDeclaration: Declaration | undefined, firstType: Type, nextDeclaration: Declaration, nextType: Type): void {
2686326863
const nextDeclarationName = getNameOfDeclaration(nextDeclaration);
2686426864
const message = nextDeclaration.kind === SyntaxKind.PropertyDeclaration || nextDeclaration.kind === SyntaxKind.PropertySignature
2686526865
? Diagnostics.Subsequent_property_declarations_must_have_the_same_type_Property_0_must_be_of_type_1_but_here_has_type_2
2686626866
: Diagnostics.Subsequent_variable_declarations_must_have_the_same_type_Variable_0_must_be_of_type_1_but_here_has_type_2;
26867-
error(
26867+
const declName = declarationNameToString(nextDeclarationName);
26868+
const err = error(
2686826869
nextDeclarationName,
2686926870
message,
26870-
declarationNameToString(nextDeclarationName),
26871+
declName,
2687126872
typeToString(firstType),
26872-
typeToString(nextType));
26873+
typeToString(nextType)
26874+
);
26875+
if (firstDeclaration) {
26876+
addRelatedInfo(err,
26877+
createDiagnosticForNode(firstDeclaration, Diagnostics._0_was_also_declared_here, declName)
26878+
);
26879+
}
2687326880
}
2687426881

2687526882
function areDeclarationFlagsIdentical(left: Declaration, right: Declaration) {

0 commit comments

Comments
 (0)