TS8005
On this page

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

example.shade.ts
"use typeshade"
@fragment
export 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.

example.shade.ts
"use typeshade"
@fragment
export 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> is var<storage, read> and storage<T, "read_write"> is var<storage, read_write>.
Rule 6.10 Test
A local const binds 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_x when nothing in the program writes it, and a module variable in the per-invocation space (Rule 6.5) when something does; a readonly static is never written.
Rule 8.14 Test
A constructor’s parameter property (constructor(public x: f32), or private, protected or readonly in place of public) 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 const that holds an arrow function or a function expression, or a function declaration, 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:

Edit this page Report a problem