Skip to content

Commit 6469622

Browse files
Merge pull request #39418 from a-tarasyuk/feat/25259-diagnostic
feat(25259): Better error report for equals instead of colon in object literals / change diagnostic message
2 parents 77bf204 + 9f85859 commit 6469622

5 files changed

+7
-7
lines changed

src/compiler/checker.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -38266,7 +38266,7 @@ namespace ts {
3826638266
if (prop.kind === SyntaxKind.ShorthandPropertyAssignment && !inDestructuring && prop.objectAssignmentInitializer) {
3826738267
// having objectAssignmentInitializer is only valid in ObjectAssignmentPattern
3826838268
// outside of destructuring it is a syntax error
38269-
return grammarErrorOnNode(prop.equalsToken!, Diagnostics.Did_you_mean_to_use_a_Colon_When_following_property_names_in_an_object_literal_implies_a_destructuring_assignment);
38269+
return grammarErrorOnNode(prop.equalsToken!, Diagnostics.Did_you_mean_to_use_a_Colon_An_can_only_follow_a_property_name_when_the_containing_object_literal_is_part_of_a_destructuring_pattern);
3827038270
}
3827138271

3827238272
if (name.kind === SyntaxKind.PrivateIdentifier) {

src/compiler/diagnosticMessages.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -880,7 +880,7 @@
880880
"category": "Error",
881881
"code": 1308
882882
},
883-
"Did you mean to use a ':'? When following property names in an object literal, '=' implies a destructuring assignment.": {
883+
"Did you mean to use a ':'? An '=' can only follow a property name when the containing object literal is part of a destructuring pattern.": {
884884
"category": "Error",
885885
"code": 1312
886886
},

src/services/codefixes/fixPropertyAssignment.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
namespace ts.codefix {
33
const fixId = "fixPropertyAssignment";
44
const errorCodes = [
5-
Diagnostics.Did_you_mean_to_use_a_Colon_When_following_property_names_in_an_object_literal_implies_a_destructuring_assignment.code
5+
Diagnostics.Did_you_mean_to_use_a_Colon_An_can_only_follow_a_property_name_when_the_containing_object_literal_is_part_of_a_destructuring_pattern.code
66
];
77

88
registerCodeFix({

tests/baselines/reference/shorthandPropertyAssignmentsInDestructuring.errors.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ tests/cases/compiler/shorthandPropertyAssignmentsInDestructuring.ts(85,19): erro
1111
Types of property 'x' are incompatible.
1212
Type 'number' is not assignable to type 'string'.
1313
tests/cases/compiler/shorthandPropertyAssignmentsInDestructuring.ts(85,26): error TS2322: Type 'number' is not assignable to type 'string'.
14-
tests/cases/compiler/shorthandPropertyAssignmentsInDestructuring.ts(111,14): error TS1312: Did you mean to use a ':'? When following property names in an object literal, '=' implies a destructuring assignment.
14+
tests/cases/compiler/shorthandPropertyAssignmentsInDestructuring.ts(111,14): error TS1312: Did you mean to use a ':'? An '=' can only follow a property name when the containing object literal is part of a destructuring pattern.
1515

1616

1717
==== tests/cases/compiler/shorthandPropertyAssignmentsInDestructuring.ts (12 errors) ====
@@ -153,7 +153,7 @@ tests/cases/compiler/shorthandPropertyAssignmentsInDestructuring.ts(111,14): err
153153
(function() {
154154
let a = { s = 5 };
155155
~
156-
!!! error TS1312: Did you mean to use a ':'? When following property names in an object literal, '=' implies a destructuring assignment.
156+
!!! error TS1312: Did you mean to use a ':'? An '=' can only follow a property name when the containing object literal is part of a destructuring pattern.
157157
});
158158

159159
function foo({a = 4, b = { x: 5 }}) {

tests/baselines/reference/shorthandPropertyAssignmentsInDestructuring_ES6.errors.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ tests/cases/compiler/shorthandPropertyAssignmentsInDestructuring_ES6.ts(85,19):
1111
Types of property 'x' are incompatible.
1212
Type 'number' is not assignable to type 'string'.
1313
tests/cases/compiler/shorthandPropertyAssignmentsInDestructuring_ES6.ts(85,26): error TS2322: Type 'number' is not assignable to type 'string'.
14-
tests/cases/compiler/shorthandPropertyAssignmentsInDestructuring_ES6.ts(111,14): error TS1312: Did you mean to use a ':'? When following property names in an object literal, '=' implies a destructuring assignment.
14+
tests/cases/compiler/shorthandPropertyAssignmentsInDestructuring_ES6.ts(111,14): error TS1312: Did you mean to use a ':'? An '=' can only follow a property name when the containing object literal is part of a destructuring pattern.
1515

1616

1717
==== tests/cases/compiler/shorthandPropertyAssignmentsInDestructuring_ES6.ts (12 errors) ====
@@ -153,7 +153,7 @@ tests/cases/compiler/shorthandPropertyAssignmentsInDestructuring_ES6.ts(111,14):
153153
(function() {
154154
let a = { s = 5 };
155155
~
156-
!!! error TS1312: Did you mean to use a ':'? When following property names in an object literal, '=' implies a destructuring assignment.
156+
!!! error TS1312: Did you mean to use a ':'? An '=' can only follow a property name when the containing object literal is part of a destructuring pattern.
157157
});
158158

159159
function foo({a = 4, b = { x: 5 }}) {

0 commit comments

Comments
 (0)