---
title: "TS8005 CONST_ASSIGN: TypeShade 컴파일러가 진단에 붙이는 오류 코드 한 가지"
description: "TS8005 CONST_ASSIGN, TypeShade 컴파일러의 오류 코드입니다. 바뀔 수 없는 이름이나 자리에 값을 대입합니다."
url: https://typeshade.dev/ko/reference/errors/ts8005/
language: ko
---

# `TS8005`

프런트엔드 코드 `CONST_ASSIGN`

바뀔 수 없는 이름이나 자리에 값을 대입합니다. `const`에 담은 수나 벡터, `const` 벡터나 행렬의 성분, `readonly` 필드나 static, 그리고 `readonly`나 `"read"`로 쓰지 않겠다고 약속한 스토리지 바인딩에는 값을 쓸 수 없습니다. `const` 객체의 필드나 원소에 쓰는 것은 여기에 해당하지 않습니다. `const`는 객체를 담고 있을 뿐이고, 객체는 JavaScript에서처럼 계속 쓸 수 있기 때문입니다([규칙 6.10](https://typeshade.dev/ko/reference/rules/6-10/)).

레지스트리에는 이 상수에 대한 문서 주석이 없습니다. 그래서 위 설명은 컴파일러가 이 코드와 함께 내는 메시지를 보고 이 사이트가 쓴 것입니다.

레지스트리 설명과 컴파일러 메시지는 컴파일러 원문이라 한국어 페이지에서도 영어로 둡니다.

## 예제

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.)
}
```

빌드할 때 고정된 컴파일러로 이 프로그램을 컴파일하면 다음 진단이 나옵니다.

**TS8005** error, 6행: Cannot assign to "g" — it is declared with const.

## 고치는 법

같은 프로그램을 고친 모습입니다. 진단 없이 컴파일됩니다.

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.)
}
```

## 이 코드가 적용하는 규칙

**[규칙 6.2](https://typeshade.dev/ko/reference/rules/6-2/) 테스트**

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>`.

**[규칙 6.10](https://typeshade.dev/ko/reference/rules/6-10/) 테스트**

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

**[규칙 8.13](https://typeshade.dev/ko/reference/rules/8-13/) 테스트**

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/ko/reference/rules/6-5/)) when something does; a `readonly` static is never written.

**[규칙 8.14](https://typeshade.dev/ko/reference/rules/8-14/) 테스트**

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.

**[규칙 8.17](https://typeshade.dev/ko/reference/rules/8-17/) 테스트**

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.

## 함께 보기

**[`SD0107`](https://typeshade.dev/ko/reference/errors/sd0107/)**

assignment to an immutable 'let' binding

- [타입](https://typeshade.dev/ko/guide/language/types/)
- [오류 코드](https://typeshade.dev/ko/reference/errors/)

## 소스

커밋 af54ddad5에서 컴파일러가 이 코드를 내는 곳입니다. 파일마다 한 줄씩 적었습니다.

- [`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곳)
- [`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곳)
- [`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곳)
- [`src/language-service/diagnostics/readonly-write.ts:56`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/language-service/diagnostics/readonly-write.ts#L56)
