TS8005
Front-end code CONST_ASSIGN
An assignment to a name that cannot change, such as a const or a read-only resource.
The registry has no documentation comment for this constant, so the line above is written by this site from the messages the compiler raises it with.
The registry text and every compiler message on these pages are the compiler's own English.
Example
"use typeshade"
@fragmentexport function main(@location(0) uv: vec2): vec4 { const g = uv.x g = g * 2. return vec4(g, g, g, 1.)}Compiled at build time against the pinned compiler, this program gets:
TS8005 error, line 6: Cannot assign to "g" — it is declared with const.
How to fix it
The same program, corrected. It compiles with no diagnostic.
"use typeshade"
@fragmentexport function main(@location(0) uv: vec2): vec4 { let g = uv.x g = g * 2. return vec4(g, g, g, 1.)}The rules this enforces
- Rule 6.2 Test
- A storage binding’s access mode is its second type argument:
storage<T>isvar<storage, read>andstorage<T, "read_write">isvar<storage, read_write>. - Rule 6.10 Test
- A local
constbinds its name once and leaves what it holds as writable as TypeScript does. - Rule 8.13 Test
- A static field must be a module constant
Owner_xwhen nothing in the program writes it, and a module variable in the per-invocation space (Rule 6.5) when something does; areadonlystatic is never written. - Rule 8.14 Test
- A constructor’s parameter property (
constructor(public x: f32), orprivate,protectedorreadonlyin place ofpublic) is a field of its class, at the constructor’s place among the members, which the constructor assigns from the parameter before the field initializers run. - Rule 8.17 Test
- A local function (a
constthat holds an arrow function or a function expression, or afunctiondeclaration, written inside a function’s body) is a function of the module named after the body that declares it (surface §14), and it may read and write the variables of the functions around it, as a TypeScript closure does.
See also
-
SD0107 - assignment to an immutable 'let' binding
Source
Where the compiler raises this code at commit 26de7be8, one line per file: