mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
add new error message 'Cannot assign to {0} because it is a constant.'
This commit is contained in:
@@ -15891,7 +15891,12 @@ namespace ts {
|
||||
return errorType;
|
||||
}
|
||||
if (isReadonlySymbol(localOrExportSymbol)) {
|
||||
error(node, Diagnostics.Cannot_assign_to_0_because_it_is_a_constant_or_a_read_only_property, symbolToString(symbol));
|
||||
if (localOrExportSymbol.flags & SymbolFlags.Variable) {
|
||||
error(node, Diagnostics.Cannot_assign_to_0_because_it_is_a_constant, symbolToString(symbol));
|
||||
}
|
||||
else {
|
||||
error(node, Diagnostics.Cannot_assign_to_0_because_it_is_a_constant_or_a_read_only_property, symbolToString(symbol));
|
||||
}
|
||||
return errorType;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2124,6 +2124,10 @@
|
||||
"category": "Error",
|
||||
"code": 2587
|
||||
},
|
||||
"Cannot assign to '{0}' because it is a constant.": {
|
||||
"category": "Error",
|
||||
"code": 2588
|
||||
},
|
||||
"JSX element attributes type '{0}' may not be a union type.": {
|
||||
"category": "Error",
|
||||
"code": 2600
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
tests/cases/compiler/file2.ts(1,1): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property.
|
||||
tests/cases/compiler/file2.ts(1,1): error TS2588: Cannot assign to 'x' because it is a constant.
|
||||
|
||||
|
||||
==== tests/cases/compiler/file1.ts (0 errors) ====
|
||||
@@ -7,4 +7,4 @@ tests/cases/compiler/file2.ts(1,1): error TS2540: Cannot assign to 'x' because i
|
||||
==== tests/cases/compiler/file2.ts (1 errors) ====
|
||||
x++;
|
||||
~
|
||||
!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property.
|
||||
!!! error TS2588: Cannot assign to 'x' because it is a constant.
|
||||
@@ -1,20 +1,20 @@
|
||||
tests/cases/compiler/constDeclarations-access2.ts(4,1): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property.
|
||||
tests/cases/compiler/constDeclarations-access2.ts(5,1): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property.
|
||||
tests/cases/compiler/constDeclarations-access2.ts(6,1): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property.
|
||||
tests/cases/compiler/constDeclarations-access2.ts(7,1): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property.
|
||||
tests/cases/compiler/constDeclarations-access2.ts(8,1): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property.
|
||||
tests/cases/compiler/constDeclarations-access2.ts(9,1): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property.
|
||||
tests/cases/compiler/constDeclarations-access2.ts(10,1): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property.
|
||||
tests/cases/compiler/constDeclarations-access2.ts(11,1): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property.
|
||||
tests/cases/compiler/constDeclarations-access2.ts(12,1): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property.
|
||||
tests/cases/compiler/constDeclarations-access2.ts(13,1): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property.
|
||||
tests/cases/compiler/constDeclarations-access2.ts(14,1): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property.
|
||||
tests/cases/compiler/constDeclarations-access2.ts(15,1): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property.
|
||||
tests/cases/compiler/constDeclarations-access2.ts(17,1): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property.
|
||||
tests/cases/compiler/constDeclarations-access2.ts(18,1): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property.
|
||||
tests/cases/compiler/constDeclarations-access2.ts(19,3): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property.
|
||||
tests/cases/compiler/constDeclarations-access2.ts(20,3): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property.
|
||||
tests/cases/compiler/constDeclarations-access2.ts(22,5): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property.
|
||||
tests/cases/compiler/constDeclarations-access2.ts(4,1): error TS2588: Cannot assign to 'x' because it is a constant.
|
||||
tests/cases/compiler/constDeclarations-access2.ts(5,1): error TS2588: Cannot assign to 'x' because it is a constant.
|
||||
tests/cases/compiler/constDeclarations-access2.ts(6,1): error TS2588: Cannot assign to 'x' because it is a constant.
|
||||
tests/cases/compiler/constDeclarations-access2.ts(7,1): error TS2588: Cannot assign to 'x' because it is a constant.
|
||||
tests/cases/compiler/constDeclarations-access2.ts(8,1): error TS2588: Cannot assign to 'x' because it is a constant.
|
||||
tests/cases/compiler/constDeclarations-access2.ts(9,1): error TS2588: Cannot assign to 'x' because it is a constant.
|
||||
tests/cases/compiler/constDeclarations-access2.ts(10,1): error TS2588: Cannot assign to 'x' because it is a constant.
|
||||
tests/cases/compiler/constDeclarations-access2.ts(11,1): error TS2588: Cannot assign to 'x' because it is a constant.
|
||||
tests/cases/compiler/constDeclarations-access2.ts(12,1): error TS2588: Cannot assign to 'x' because it is a constant.
|
||||
tests/cases/compiler/constDeclarations-access2.ts(13,1): error TS2588: Cannot assign to 'x' because it is a constant.
|
||||
tests/cases/compiler/constDeclarations-access2.ts(14,1): error TS2588: Cannot assign to 'x' because it is a constant.
|
||||
tests/cases/compiler/constDeclarations-access2.ts(15,1): error TS2588: Cannot assign to 'x' because it is a constant.
|
||||
tests/cases/compiler/constDeclarations-access2.ts(17,1): error TS2588: Cannot assign to 'x' because it is a constant.
|
||||
tests/cases/compiler/constDeclarations-access2.ts(18,1): error TS2588: Cannot assign to 'x' because it is a constant.
|
||||
tests/cases/compiler/constDeclarations-access2.ts(19,3): error TS2588: Cannot assign to 'x' because it is a constant.
|
||||
tests/cases/compiler/constDeclarations-access2.ts(20,3): error TS2588: Cannot assign to 'x' because it is a constant.
|
||||
tests/cases/compiler/constDeclarations-access2.ts(22,5): error TS2588: Cannot assign to 'x' because it is a constant.
|
||||
|
||||
|
||||
==== tests/cases/compiler/constDeclarations-access2.ts (17 errors) ====
|
||||
@@ -23,57 +23,57 @@ tests/cases/compiler/constDeclarations-access2.ts(22,5): error TS2540: Cannot as
|
||||
// Errors
|
||||
x = 1;
|
||||
~
|
||||
!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property.
|
||||
!!! error TS2588: Cannot assign to 'x' because it is a constant.
|
||||
x += 2;
|
||||
~
|
||||
!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property.
|
||||
!!! error TS2588: Cannot assign to 'x' because it is a constant.
|
||||
x -= 3;
|
||||
~
|
||||
!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property.
|
||||
!!! error TS2588: Cannot assign to 'x' because it is a constant.
|
||||
x *= 4;
|
||||
~
|
||||
!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property.
|
||||
!!! error TS2588: Cannot assign to 'x' because it is a constant.
|
||||
x /= 5;
|
||||
~
|
||||
!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property.
|
||||
!!! error TS2588: Cannot assign to 'x' because it is a constant.
|
||||
x %= 6;
|
||||
~
|
||||
!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property.
|
||||
!!! error TS2588: Cannot assign to 'x' because it is a constant.
|
||||
x <<= 7;
|
||||
~
|
||||
!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property.
|
||||
!!! error TS2588: Cannot assign to 'x' because it is a constant.
|
||||
x >>= 8;
|
||||
~
|
||||
!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property.
|
||||
!!! error TS2588: Cannot assign to 'x' because it is a constant.
|
||||
x >>>= 9;
|
||||
~
|
||||
!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property.
|
||||
!!! error TS2588: Cannot assign to 'x' because it is a constant.
|
||||
x &= 10;
|
||||
~
|
||||
!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property.
|
||||
!!! error TS2588: Cannot assign to 'x' because it is a constant.
|
||||
x |= 11;
|
||||
~
|
||||
!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property.
|
||||
!!! error TS2588: Cannot assign to 'x' because it is a constant.
|
||||
x ^= 12;
|
||||
~
|
||||
!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property.
|
||||
!!! error TS2588: Cannot assign to 'x' because it is a constant.
|
||||
|
||||
x++;
|
||||
~
|
||||
!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property.
|
||||
!!! error TS2588: Cannot assign to 'x' because it is a constant.
|
||||
x--;
|
||||
~
|
||||
!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property.
|
||||
!!! error TS2588: Cannot assign to 'x' because it is a constant.
|
||||
++x;
|
||||
~
|
||||
!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property.
|
||||
!!! error TS2588: Cannot assign to 'x' because it is a constant.
|
||||
--x;
|
||||
~
|
||||
!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property.
|
||||
!!! error TS2588: Cannot assign to 'x' because it is a constant.
|
||||
|
||||
++((x));
|
||||
~
|
||||
!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property.
|
||||
!!! error TS2588: Cannot assign to 'x' because it is a constant.
|
||||
|
||||
// OK
|
||||
var a = x + 1;
|
||||
|
||||
@@ -4,7 +4,7 @@ tests/cases/compiler/constDeclarations-errors.ts(4,7): error TS1155: 'const' dec
|
||||
tests/cases/compiler/constDeclarations-errors.ts(4,11): error TS1155: 'const' declarations must be initialized.
|
||||
tests/cases/compiler/constDeclarations-errors.ts(4,15): error TS1155: 'const' declarations must be initialized.
|
||||
tests/cases/compiler/constDeclarations-errors.ts(4,27): error TS1155: 'const' declarations must be initialized.
|
||||
tests/cases/compiler/constDeclarations-errors.ts(9,27): error TS2540: Cannot assign to 'c8' because it is a constant or a read-only property.
|
||||
tests/cases/compiler/constDeclarations-errors.ts(9,27): error TS2588: Cannot assign to 'c8' because it is a constant.
|
||||
tests/cases/compiler/constDeclarations-errors.ts(12,11): error TS1155: 'const' declarations must be initialized.
|
||||
tests/cases/compiler/constDeclarations-errors.ts(15,20): error TS1155: 'const' declarations must be initialized.
|
||||
|
||||
@@ -32,7 +32,7 @@ tests/cases/compiler/constDeclarations-errors.ts(15,20): error TS1155: 'const' d
|
||||
// error, assigning to a const
|
||||
for(const c8 = 0; c8 < 1; c8++) { }
|
||||
~~
|
||||
!!! error TS2540: Cannot assign to 'c8' because it is a constant or a read-only property.
|
||||
!!! error TS2588: Cannot assign to 'c8' because it is a constant.
|
||||
|
||||
// error, can not be unintalized
|
||||
for(const c9; c9 < 1;) { }
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
tests/cases/compiler/constWithNonNull.ts(4,1): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property.
|
||||
tests/cases/compiler/constWithNonNull.ts(4,1): error TS2588: Cannot assign to 'x' because it is a constant.
|
||||
|
||||
|
||||
==== tests/cases/compiler/constWithNonNull.ts (1 errors) ====
|
||||
@@ -7,5 +7,5 @@ tests/cases/compiler/constWithNonNull.ts(4,1): error TS2540: Cannot assign to 'x
|
||||
declare const x: number | undefined;
|
||||
x!++;
|
||||
~
|
||||
!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property.
|
||||
!!! error TS2588: Cannot assign to 'x' because it is a constant.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
tests/cases/conformance/es6/for-ofStatements/for-of2.ts(1,7): error TS1155: 'const' declarations must be initialized.
|
||||
tests/cases/conformance/es6/for-ofStatements/for-of2.ts(2,6): error TS2540: Cannot assign to 'v' because it is a constant or a read-only property.
|
||||
tests/cases/conformance/es6/for-ofStatements/for-of2.ts(2,6): error TS2588: Cannot assign to 'v' because it is a constant.
|
||||
|
||||
|
||||
==== tests/cases/conformance/es6/for-ofStatements/for-of2.ts (2 errors) ====
|
||||
@@ -8,4 +8,4 @@ tests/cases/conformance/es6/for-ofStatements/for-of2.ts(2,6): error TS2540: Cann
|
||||
!!! error TS1155: 'const' declarations must be initialized.
|
||||
for (v of []) { }
|
||||
~
|
||||
!!! error TS2540: Cannot assign to 'v' because it is a constant or a read-only property.
|
||||
!!! error TS2588: Cannot assign to 'v' because it is a constant.
|
||||
@@ -1,7 +1,7 @@
|
||||
tests/cases/compiler/redefineArray.ts(1,1): error TS2540: Cannot assign to 'Array' because it is a constant or a read-only property.
|
||||
tests/cases/compiler/redefineArray.ts(1,1): error TS2588: Cannot assign to 'Array' because it is a constant.
|
||||
|
||||
|
||||
==== tests/cases/compiler/redefineArray.ts (1 errors) ====
|
||||
Array = function (n:number, s:string) {return n;};
|
||||
~~~~~
|
||||
!!! error TS2540: Cannot assign to 'Array' because it is a constant or a read-only property.
|
||||
!!! error TS2588: Cannot assign to 'Array' because it is a constant.
|
||||
Reference in New Issue
Block a user