---
title: "TS8005 CONST_ASSIGN: an error code of the TypeShade compiler"
description: "TS8005 CONST_ASSIGN, an error code of the TypeShade compiler. An assignment to a name or a place that cannot change: a const number or vector…"
url: https://typeshade.dev/reference/errors/ts8005/
language: en
---

# `TS8005`

Front-end code `CONST_ASSIGN`

An assignment to a name or a place that cannot change: a `const` number or vector, a component of a `const` vector or matrix, a `readonly` field or static, or a storage binding that `readonly` or `"read"` promises is never written. A write to a field or an element of a `const` object is not one of these, because the `const` holds the object and the object stays writable, as in JavaScript ([Rule 6.10](https://typeshade.dev/reference/rules/6-10/)).

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

```ts
"use typeshade"

@fragment
export function main(uv: location<0, 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

```ts
"use typeshade"

@fragment
export function main(uv: location<0, vec2>): vec4 {
  let g = uv.x
  g = g * 2.
  return vec4(g, g, g, 1.)
}
```

## The rules this enforces

**[Rule 6.2](https://typeshade.dev/reference/rules/6-2/) Test**

A storage binding’s access mode is inferred from what the program does: a binding that some entry writes, by assignment, a mutating method, an atomic builtin, or a write through a function or a reference parameter, is `var<storage, read_write>`, and every other storage binding is `var<storage, read>`.

**[Rule 6.10](https://typeshade.dev/reference/rules/6-10/) Test**

A local `const` binds its name once and leaves what it holds as writable as TypeScript does.

**[Rule 8.13](https://typeshade.dev/reference/rules/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](https://typeshade.dev/reference/rules/6-5/)) when something does; a `readonly` static is never written.

**[Rule 8.14](https://typeshade.dev/reference/rules/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](https://typeshade.dev/reference/rules/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`](https://typeshade.dev/reference/errors/sd0107/)**

assignment to an immutable 'let' binding

- [Types](https://typeshade.dev/guide/language/types/)
- [Error codes](https://typeshade.dev/reference/errors/)

## Source

Where the compiler raises this code at commit af54ddad5, one line per file:

- [`src/compiler/ts/lower/atomics.ts:132`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/lower/atomics.ts#L132)
- [`src/compiler/ts/lower/class-access.ts:317`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/lower/class-access.ts#L317) (3 sites)
- [`src/compiler/ts/lower/control/for-update.ts:87`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/lower/control/for-update.ts#L87) (2 sites)
- [`src/compiler/ts/lower/optional-values/nullish.ts:136`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/lower/optional-values/nullish.ts#L136)
- [`src/compiler/ts/lower/readonly-promise.ts:223`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/lower/readonly-promise.ts#L223)
- [`src/compiler/ts/lower/statement/lvalue.ts:138`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/lower/statement/lvalue.ts#L138)
- [`src/compiler/ts/lower/statement/writable.ts:67`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/lower/statement/writable.ts#L67) (5 sites)
- [`src/language-service/diagnostics/readonly-write.ts:56`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/language-service/diagnostics/readonly-write.ts#L56)
