Skip to content

Commit 19e54fe

Browse files
Improve error message spans when object literals have excess properties.
1 parent 5542e39 commit 19e54fe

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/compiler/checker.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4593,6 +4593,16 @@ namespace ts {
45934593
}
45944594
return result !== Ternary.False;
45954595

4596+
function reportErrorAndTryImproveErrorNode(
4597+
newErrorNode: Node,
4598+
message: DiagnosticMessage,
4599+
arg0?: string,
4600+
arg1?: string,
4601+
arg2?: string) {
4602+
errorNode = newErrorNode || errorNode;
4603+
reportError(message, arg0, arg1, arg2);
4604+
}
4605+
45964606
function reportError(message: DiagnosticMessage, arg0?: string, arg1?: string, arg2?: string): void {
45974607
errorInfo = chainDiagnosticMessages(errorInfo, message, arg0, arg1, arg2);
45984608
}
@@ -4767,7 +4777,8 @@ namespace ts {
47674777
for (let prop of getPropertiesOfObjectType(source)) {
47684778
if (!isKnownProperty(target, prop.name)) {
47694779
if (reportErrors) {
4770-
reportError(Diagnostics.Object_literal_may_only_specify_known_properties_and_0_does_not_exist_in_type_1, symbolToString(prop), typeToString(target));
4780+
reportErrorAndTryImproveErrorNode(prop.valueDeclaration,
4781+
Diagnostics.Object_literal_may_only_specify_known_properties_and_0_does_not_exist_in_type_1, symbolToString(prop), typeToString(target));
47714782
}
47724783
return true;
47734784
}

0 commit comments

Comments
 (0)