TS8005
프런트엔드 코드 CONST_ASSIGN
const나 읽기 전용 리소스처럼 바뀔 수 없는 이름에 값을 대입합니다.
레지스트리에는 이 상수에 대한 문서 주석이 없습니다. 그래서 위 설명은 컴파일러가 이 코드와 함께 내는 메시지를 보고 이 사이트가 쓴 것입니다.
레지스트리 설명과 컴파일러 메시지는 컴파일러 원문이라 한국어 페이지에서도 영어로 둡니다.
예제
"use typeshade"
@fragmentexport function main(@location(0) uv: 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.
고치는 법
같은 프로그램을 고친 모습입니다. 진단 없이 컴파일됩니다.
"use typeshade"
@fragmentexport function main(@location(0) uv: vec2): vec4 { let g = uv.x g = g * 2. return vec4(g, g, g, 1.)}이 코드가 적용하는 규칙
- 규칙 6.2 테스트
- A storage binding’s access mode is its second type argument:
storage<T>isvar<storage, read>andstorage<T, "read_write">isvar<storage, read_write>. - 규칙 6.10 테스트
- A local
constbinds its name once and leaves what it holds as writable as TypeScript does. - 규칙 8.13 테스트
- 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. - 규칙 8.14 테스트
- 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. - 규칙 8.17 테스트
- 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.
함께 보기
-
SD0107 - assignment to an immutable 'let' binding
소스
커밋 c66579bf에서 컴파일러가 이 코드를 내는 곳입니다. 파일마다 한 줄씩 적었습니다.