Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit a316cb3

Browse filesBrowse files
committed
Switch to multiple error messages
1 parent 658eec3 commit a316cb3
Copy full SHA for a316cb3

33 files changed

+274-246Lines changed: 274 additions & 246 deletions
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎src/compiler/checker.ts‎

Copy file name to clipboardExpand all lines: src/compiler/checker.ts
+9-1Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23691,7 +23691,15 @@ namespace ts {
2369123691
if (assignmentKind) {
2369223692
if (!(localOrExportSymbol.flags & SymbolFlags.Variable) &&
2369323693
!(isInJSFile(node) && localOrExportSymbol.flags & SymbolFlags.ValueModule)) {
23694-
error(node, Diagnostics.Cannot_assign_to_0_because_it_is_immutable, symbolToString(symbol));
23694+
const ff = localOrExportSymbol.flags
23695+
const assignmentError = ff & SymbolFlags.Enum ? Diagnostics.Cannot_assign_to_0_because_it_is_an_enum
23696+
: ff & SymbolFlags.Class ? Diagnostics.Cannot_assign_to_0_because_it_is_a_class
23697+
: ff & SymbolFlags.Module ? Diagnostics.Cannot_assign_to_0_because_it_is_a_namespace
23698+
: ff & SymbolFlags.Function ? Diagnostics.Cannot_assign_to_0_because_it_is_a_function
23699+
: ff & SymbolFlags.Alias ? Diagnostics.Cannot_assign_to_0_because_it_is_an_import
23700+
: Diagnostics.Cannot_assign_to_0_because_it_is_not_a_variable;
23701+
23702+
error(node, assignmentError, symbolToString(symbol));
2369523703
return errorType;
2369623704
}
2369723705
if (isReadonlySymbol(localOrExportSymbol)) {
Collapse file

‎src/compiler/diagnosticMessages.json‎

Copy file name to clipboardExpand all lines: src/compiler/diagnosticMessages.json
+21-1Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2322,7 +2322,7 @@
23222322
"category": "Error",
23232323
"code": 2538
23242324
},
2325-
"Cannot assign to '{0}' because it is immutable.": {
2325+
"Cannot assign to '{0}' because it is not a variable.": {
23262326
"category": "Error",
23272327
"code": 2539
23282328
},
@@ -2654,6 +2654,26 @@
26542654
"category": "Error",
26552655
"code": 2627
26562656
},
2657+
"Cannot assign to '{0}' because it is an enum.": {
2658+
"category": "Error",
2659+
"code": 2628
2660+
},
2661+
"Cannot assign to '{0}' because it is a class.": {
2662+
"category": "Error",
2663+
"code": 2629
2664+
},
2665+
"Cannot assign to '{0}' because it is a function.": {
2666+
"category": "Error",
2667+
"code": 2630
2668+
},
2669+
"Cannot assign to '{0}' because it is a namespace.": {
2670+
"category": "Error",
2671+
"code": 2631
2672+
},
2673+
"Cannot assign to '{0}' because it is an import.": {
2674+
"category": "Error",
2675+
"code": 2632
2676+
},
26572677

26582678
"Cannot augment module '{0}' with value exports because it resolves to a non-module entity.": {
26592679
"category": "Error",
Collapse file
+24-24Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,53 @@
1-
tests/cases/compiler/arithAssignTyping.ts(3,1): error TS2539: Cannot assign to 'f' because it is immutable.
2-
tests/cases/compiler/arithAssignTyping.ts(4,1): error TS2539: Cannot assign to 'f' because it is immutable.
3-
tests/cases/compiler/arithAssignTyping.ts(5,1): error TS2539: Cannot assign to 'f' because it is immutable.
4-
tests/cases/compiler/arithAssignTyping.ts(6,1): error TS2539: Cannot assign to 'f' because it is immutable.
5-
tests/cases/compiler/arithAssignTyping.ts(7,1): error TS2539: Cannot assign to 'f' because it is immutable.
6-
tests/cases/compiler/arithAssignTyping.ts(8,1): error TS2539: Cannot assign to 'f' because it is immutable.
7-
tests/cases/compiler/arithAssignTyping.ts(9,1): error TS2539: Cannot assign to 'f' because it is immutable.
8-
tests/cases/compiler/arithAssignTyping.ts(10,1): error TS2539: Cannot assign to 'f' because it is immutable.
9-
tests/cases/compiler/arithAssignTyping.ts(11,1): error TS2539: Cannot assign to 'f' because it is immutable.
10-
tests/cases/compiler/arithAssignTyping.ts(12,1): error TS2539: Cannot assign to 'f' because it is immutable.
11-
tests/cases/compiler/arithAssignTyping.ts(13,1): error TS2539: Cannot assign to 'f' because it is immutable.
12-
tests/cases/compiler/arithAssignTyping.ts(14,1): error TS2539: Cannot assign to 'f' because it is immutable.
1+
tests/cases/compiler/arithAssignTyping.ts(3,1): error TS2629: Cannot assign to 'f' because it is a class.
2+
tests/cases/compiler/arithAssignTyping.ts(4,1): error TS2629: Cannot assign to 'f' because it is a class.
3+
tests/cases/compiler/arithAssignTyping.ts(5,1): error TS2629: Cannot assign to 'f' because it is a class.
4+
tests/cases/compiler/arithAssignTyping.ts(6,1): error TS2629: Cannot assign to 'f' because it is a class.
5+
tests/cases/compiler/arithAssignTyping.ts(7,1): error TS2629: Cannot assign to 'f' because it is a class.
6+
tests/cases/compiler/arithAssignTyping.ts(8,1): error TS2629: Cannot assign to 'f' because it is a class.
7+
tests/cases/compiler/arithAssignTyping.ts(9,1): error TS2629: Cannot assign to 'f' because it is a class.
8+
tests/cases/compiler/arithAssignTyping.ts(10,1): error TS2629: Cannot assign to 'f' because it is a class.
9+
tests/cases/compiler/arithAssignTyping.ts(11,1): error TS2629: Cannot assign to 'f' because it is a class.
10+
tests/cases/compiler/arithAssignTyping.ts(12,1): error TS2629: Cannot assign to 'f' because it is a class.
11+
tests/cases/compiler/arithAssignTyping.ts(13,1): error TS2629: Cannot assign to 'f' because it is a class.
12+
tests/cases/compiler/arithAssignTyping.ts(14,1): error TS2629: Cannot assign to 'f' because it is a class.
1313

1414

1515
==== tests/cases/compiler/arithAssignTyping.ts (12 errors) ====
1616
class f { }
1717

1818
f += ''; // error
1919
~
20-
!!! error TS2539: Cannot assign to 'f' because it is immutable.
20+
!!! error TS2629: Cannot assign to 'f' because it is a class.
2121
f += 1; // error
2222
~
23-
!!! error TS2539: Cannot assign to 'f' because it is immutable.
23+
!!! error TS2629: Cannot assign to 'f' because it is a class.
2424
f -= 1; // error
2525
~
26-
!!! error TS2539: Cannot assign to 'f' because it is immutable.
26+
!!! error TS2629: Cannot assign to 'f' because it is a class.
2727
f *= 1; // error
2828
~
29-
!!! error TS2539: Cannot assign to 'f' because it is immutable.
29+
!!! error TS2629: Cannot assign to 'f' because it is a class.
3030
f /= 1; // error
3131
~
32-
!!! error TS2539: Cannot assign to 'f' because it is immutable.
32+
!!! error TS2629: Cannot assign to 'f' because it is a class.
3333
f %= 1; // error
3434
~
35-
!!! error TS2539: Cannot assign to 'f' because it is immutable.
35+
!!! error TS2629: Cannot assign to 'f' because it is a class.
3636
f &= 1; // error
3737
~
38-
!!! error TS2539: Cannot assign to 'f' because it is immutable.
38+
!!! error TS2629: Cannot assign to 'f' because it is a class.
3939
f |= 1; // error
4040
~
41-
!!! error TS2539: Cannot assign to 'f' because it is immutable.
41+
!!! error TS2629: Cannot assign to 'f' because it is a class.
4242
f <<= 1; // error
4343
~
44-
!!! error TS2539: Cannot assign to 'f' because it is immutable.
44+
!!! error TS2629: Cannot assign to 'f' because it is a class.
4545
f >>= 1; // error
4646
~
47-
!!! error TS2539: Cannot assign to 'f' because it is immutable.
47+
!!! error TS2629: Cannot assign to 'f' because it is a class.
4848
f >>>= 1; // error
4949
~
50-
!!! error TS2539: Cannot assign to 'f' because it is immutable.
50+
!!! error TS2629: Cannot assign to 'f' because it is a class.
5151
f ^= 1; // error
5252
~
53-
!!! error TS2539: Cannot assign to 'f' because it is immutable.
53+
!!! error TS2629: Cannot assign to 'f' because it is a class.
Collapse file

‎tests/baselines/reference/assignAnyToEveryType.errors.txt‎

Copy file name to clipboardExpand all lines: tests/baselines/reference/assignAnyToEveryType.errors.txt
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
tests/cases/conformance/types/any/assignAnyToEveryType.ts(41,1): error TS2539: Cannot assign to 'M' because it is immutable.
1+
tests/cases/conformance/types/any/assignAnyToEveryType.ts(41,1): error TS2631: Cannot assign to 'M' because it is a namespace.
22

33

44
==== tests/cases/conformance/types/any/assignAnyToEveryType.ts (1 errors) ====
@@ -44,7 +44,7 @@ tests/cases/conformance/types/any/assignAnyToEveryType.ts(41,1): error TS2539: C
4444

4545
M = x;
4646
~
47-
!!! error TS2539: Cannot assign to 'M' because it is immutable.
47+
!!! error TS2631: Cannot assign to 'M' because it is a namespace.
4848

4949
function k<T>(a: T) {
5050
a = x;
Collapse file

‎tests/baselines/reference/assignToEnum.errors.txt‎

Copy file name to clipboardExpand all lines: tests/baselines/reference/assignToEnum.errors.txt
+4-4Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
tests/cases/compiler/assignToEnum.ts(2,1): error TS2539: Cannot assign to 'A' because it is immutable.
2-
tests/cases/compiler/assignToEnum.ts(3,1): error TS2539: Cannot assign to 'A' because it is immutable.
1+
tests/cases/compiler/assignToEnum.ts(2,1): error TS2628: Cannot assign to 'A' because it is an enum.
2+
tests/cases/compiler/assignToEnum.ts(3,1): error TS2628: Cannot assign to 'A' because it is an enum.
33
tests/cases/compiler/assignToEnum.ts(4,3): error TS2540: Cannot assign to 'foo' because it is a read-only property.
44
tests/cases/compiler/assignToEnum.ts(5,3): error TS2540: Cannot assign to 'foo' because it is a read-only property.
55

@@ -8,10 +8,10 @@ tests/cases/compiler/assignToEnum.ts(5,3): error TS2540: Cannot assign to 'foo'
88
enum A { foo, bar }
99
A = undefined; // invalid LHS
1010
~
11-
!!! error TS2539: Cannot assign to 'A' because it is immutable.
11+
!!! error TS2628: Cannot assign to 'A' because it is an enum.
1212
A = A.bar; // invalid LHS
1313
~
14-
!!! error TS2539: Cannot assign to 'A' because it is immutable.
14+
!!! error TS2628: Cannot assign to 'A' because it is an enum.
1515
A.foo = 1; // invalid LHS
1616
~~~
1717
!!! error TS2540: Cannot assign to 'foo' because it is a read-only property.
Collapse file

‎tests/baselines/reference/assignToExistingClass.errors.txt‎

Copy file name to clipboardExpand all lines: tests/baselines/reference/assignToExistingClass.errors.txt
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
tests/cases/compiler/assignToExistingClass.ts(8,13): error TS2539: Cannot assign to 'Mocked' because it is immutable.
1+
tests/cases/compiler/assignToExistingClass.ts(8,13): error TS2629: Cannot assign to 'Mocked' because it is a class.
22

33

44
==== tests/cases/compiler/assignToExistingClass.ts (1 errors) ====
@@ -11,7 +11,7 @@ tests/cases/compiler/assignToExistingClass.ts(8,13): error TS2539: Cannot assign
1111
willThrowError() {
1212
Mocked = Mocked || function () { // => Error: Invalid left-hand side of assignment expression.
1313
~~~~~~
14-
!!! error TS2539: Cannot assign to 'Mocked' because it is immutable.
14+
!!! error TS2629: Cannot assign to 'Mocked' because it is a class.
1515
return { myProp: "test" };
1616
};
1717
}
Collapse file

‎tests/baselines/reference/assignmentLHSIsValue.errors.txt‎

Copy file name to clipboardExpand all lines: tests/baselines/reference/assignmentLHSIsValue.errors.txt
+16-16Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(7
33
tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(8,21): error TS2364: The left-hand side of an assignment expression must be a variable or a property access.
44
tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(11,18): error TS2364: The left-hand side of an assignment expression must be a variable or a property access.
55
tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(13,1): error TS2364: The left-hand side of an assignment expression must be a variable or a property access.
6-
tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(17,1): error TS2539: Cannot assign to 'M' because it is immutable.
7-
tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(19,1): error TS2539: Cannot assign to 'C' because it is immutable.
8-
tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(22,1): error TS2539: Cannot assign to 'E' because it is immutable.
9-
tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(24,1): error TS2539: Cannot assign to 'foo' because it is immutable.
6+
tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(17,1): error TS2631: Cannot assign to 'M' because it is a namespace.
7+
tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(19,1): error TS2629: Cannot assign to 'C' because it is a class.
8+
tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(22,1): error TS2628: Cannot assign to 'E' because it is an enum.
9+
tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(24,1): error TS2630: Cannot assign to 'foo' because it is a function.
1010
tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(27,1): error TS2364: The left-hand side of an assignment expression must be a variable or a property access.
1111
tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(28,1): error TS2364: The left-hand side of an assignment expression must be a variable or a property access.
1212
tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(29,1): error TS2364: The left-hand side of an assignment expression must be a variable or a property access.
@@ -23,10 +23,10 @@ tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(5
2323
tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(51,11): error TS1005: ';' expected.
2424
tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(54,1): error TS2364: The left-hand side of an assignment expression must be a variable or a property access.
2525
tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(57,1): error TS2364: The left-hand side of an assignment expression must be a variable or a property access.
26-
tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(58,2): error TS2539: Cannot assign to 'M' because it is immutable.
27-
tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(59,2): error TS2539: Cannot assign to 'C' because it is immutable.
28-
tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(60,2): error TS2539: Cannot assign to 'E' because it is immutable.
29-
tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(61,2): error TS2539: Cannot assign to 'foo' because it is immutable.
26+
tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(58,2): error TS2631: Cannot assign to 'M' because it is a namespace.
27+
tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(59,2): error TS2629: Cannot assign to 'C' because it is a class.
28+
tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(60,2): error TS2628: Cannot assign to 'E' because it is an enum.
29+
tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(61,2): error TS2630: Cannot assign to 'foo' because it is a function.
3030
tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(62,1): error TS2364: The left-hand side of an assignment expression must be a variable or a property access.
3131
tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(63,1): error TS2364: The left-hand side of an assignment expression must be a variable or a property access.
3232
tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(64,1): error TS2364: The left-hand side of an assignment expression must be a variable or a property access.
@@ -67,20 +67,20 @@ tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(7
6767
module M { export var a; }
6868
M = value;
6969
~
70-
!!! error TS2539: Cannot assign to 'M' because it is immutable.
70+
!!! error TS2631: Cannot assign to 'M' because it is a namespace.
7171

7272
C = value;
7373
~
74-
!!! error TS2539: Cannot assign to 'C' because it is immutable.
74+
!!! error TS2629: Cannot assign to 'C' because it is a class.
7575

7676
enum E { }
7777
E = value;
7878
~
79-
!!! error TS2539: Cannot assign to 'E' because it is immutable.
79+
!!! error TS2628: Cannot assign to 'E' because it is an enum.
8080

8181
foo = value;
8282
~~~
83-
!!! error TS2539: Cannot assign to 'foo' because it is immutable.
83+
!!! error TS2630: Cannot assign to 'foo' because it is a function.
8484

8585
// literals
8686
null = value;
@@ -148,16 +148,16 @@ tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(7
148148
!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access.
149149
(M) = value;
150150
~
151-
!!! error TS2539: Cannot assign to 'M' because it is immutable.
151+
!!! error TS2631: Cannot assign to 'M' because it is a namespace.
152152
(C) = value;
153153
~
154-
!!! error TS2539: Cannot assign to 'C' because it is immutable.
154+
!!! error TS2629: Cannot assign to 'C' because it is a class.
155155
(E) = value;
156156
~
157-
!!! error TS2539: Cannot assign to 'E' because it is immutable.
157+
!!! error TS2628: Cannot assign to 'E' because it is an enum.
158158
(foo) = value;
159159
~~~
160-
!!! error TS2539: Cannot assign to 'foo' because it is immutable.
160+
!!! error TS2630: Cannot assign to 'foo' because it is a function.
161161
(null) = value;
162162
~~~~~~
163163
!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access.
Collapse file
+4-4Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
tests/cases/compiler/assignmentToFunction.ts(2,1): error TS2539: Cannot assign to 'fn' because it is immutable.
2-
tests/cases/compiler/assignmentToFunction.ts(8,9): error TS2539: Cannot assign to 'bar' because it is immutable.
1+
tests/cases/compiler/assignmentToFunction.ts(2,1): error TS2630: Cannot assign to 'fn' because it is a function.
2+
tests/cases/compiler/assignmentToFunction.ts(8,9): error TS2630: Cannot assign to 'bar' because it is a function.
33

44

55
==== tests/cases/compiler/assignmentToFunction.ts (2 errors) ====
66
function fn() { }
77
fn = () => 3;
88
~~
9-
!!! error TS2539: Cannot assign to 'fn' because it is immutable.
9+
!!! error TS2630: Cannot assign to 'fn' because it is a function.
1010

1111
module foo {
1212
function xyz() {
1313
function bar() {
1414
}
1515
bar = null;
1616
~~~
17-
!!! error TS2539: Cannot assign to 'bar' because it is immutable.
17+
!!! error TS2630: Cannot assign to 'bar' because it is a function.
1818
}
1919
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.