mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-30 22:32:33 -05:00
Report error only on local declaration with additional related information (#49746)
* Add test where the errors are reported in different file Test for #49739 * Report error only on local declaration with additional related information Fixes #49739 * Handle existing tests
This commit is contained in:
@@ -39552,8 +39552,9 @@ namespace ts {
|
||||
}
|
||||
const indexInfos = getApplicableIndexInfos(type, propNameType);
|
||||
const interfaceDeclaration = getObjectFlags(type) & ObjectFlags.Interface ? getDeclarationOfKind(type.symbol, SyntaxKind.InterfaceDeclaration) : undefined;
|
||||
const localPropDeclaration = declaration && declaration.kind === SyntaxKind.BinaryExpression ||
|
||||
name && name.kind === SyntaxKind.ComputedPropertyName || getParentOfSymbol(prop) === type.symbol ? declaration : undefined;
|
||||
const propDeclaration = declaration && declaration.kind === SyntaxKind.BinaryExpression ||
|
||||
name && name.kind === SyntaxKind.ComputedPropertyName ? declaration : undefined;
|
||||
const localPropDeclaration = getParentOfSymbol(prop) === type.symbol ? declaration : undefined;
|
||||
for (const info of indexInfos) {
|
||||
const localIndexDeclaration = info.declaration && getParentOfSymbol(getSymbolOfNode(info.declaration)) === type.symbol ? info.declaration : undefined;
|
||||
// We check only when (a) the property is declared in the containing type, or (b) the applicable index signature is declared
|
||||
@@ -39562,8 +39563,12 @@ namespace ts {
|
||||
const errorNode = localPropDeclaration || localIndexDeclaration ||
|
||||
(interfaceDeclaration && !some(getBaseTypes(type as InterfaceType), base => !!getPropertyOfObjectType(base, prop.escapedName) && !!getIndexTypeOfType(base, info.keyType)) ? interfaceDeclaration : undefined);
|
||||
if (errorNode && !isTypeAssignableTo(propType, info.type)) {
|
||||
error(errorNode, Diagnostics.Property_0_of_type_1_is_not_assignable_to_2_index_type_3,
|
||||
const diagnostic = createError(errorNode, Diagnostics.Property_0_of_type_1_is_not_assignable_to_2_index_type_3,
|
||||
symbolToString(prop), typeToString(propType), typeToString(info.keyType), typeToString(info.type));
|
||||
if (propDeclaration && errorNode !== propDeclaration) {
|
||||
addRelatedInfo(diagnostic, createDiagnosticForNode(propDeclaration, Diagnostics._0_is_declared_here, symbolToString(prop)));
|
||||
}
|
||||
diagnostics.add(diagnostic);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user