mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-15 03:23:08 -06:00
Add related span to original declaration on disagreeing variable/property types.
This commit is contained in:
parent
c71423edd6
commit
3f5912995b
@ -5352,7 +5352,7 @@ namespace ts {
|
||||
return type;
|
||||
}
|
||||
else if (declaredType !== errorType && type !== errorType && !isTypeIdenticalTo(declaredType, type)) {
|
||||
errorNextVariableOrPropertyDeclarationMustHaveSameType(declaredType, declaration, type);
|
||||
errorNextVariableOrPropertyDeclarationMustHaveSameType(/*firstDeclaration*/ undefined, declaredType, declaration, type);
|
||||
}
|
||||
}
|
||||
return declaredType;
|
||||
@ -26839,7 +26839,7 @@ namespace ts {
|
||||
if (type !== errorType && declarationType !== errorType &&
|
||||
!isTypeIdenticalTo(type, declarationType) &&
|
||||
!(symbol.flags & SymbolFlags.Assignment)) {
|
||||
errorNextVariableOrPropertyDeclarationMustHaveSameType(type, node, declarationType);
|
||||
errorNextVariableOrPropertyDeclarationMustHaveSameType(symbol.valueDeclaration, type, node, declarationType);
|
||||
}
|
||||
if (node.initializer) {
|
||||
checkTypeAssignableToAndOptionallyElaborate(checkExpressionCached(node.initializer), declarationType, node, node.initializer, /*headMessage*/ undefined);
|
||||
@ -26859,17 +26859,24 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
|
||||
function errorNextVariableOrPropertyDeclarationMustHaveSameType(firstType: Type, nextDeclaration: Declaration, nextType: Type): void {
|
||||
function errorNextVariableOrPropertyDeclarationMustHaveSameType(firstDeclaration: Declaration | undefined, 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_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(
|
||||
const declName = declarationNameToString(nextDeclarationName);
|
||||
const err = error(
|
||||
nextDeclarationName,
|
||||
message,
|
||||
declarationNameToString(nextDeclarationName),
|
||||
declName,
|
||||
typeToString(firstType),
|
||||
typeToString(nextType));
|
||||
typeToString(nextType)
|
||||
);
|
||||
if (firstDeclaration) {
|
||||
addRelatedInfo(err,
|
||||
createDiagnosticForNode(firstDeclaration, Diagnostics._0_was_also_declared_here, declName)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
function areDeclarationFlagsIdentical(left: Declaration, right: Declaration) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user