규칙 8.13
8장, 함수와 진입점 테스트
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.
A class inherits the statics of the classes it extends: D.K, D.f() and D.x reach the nearest class above D that declares them, and a static function or accessor D inherits must be lowered again for D.
Inside a static member this is the class the call names, D in D.f(): this.K, this.f() and this.x = v name its statics, new this(...) builds it, and a static that returns the class the call names says so with a this parameter, static make<C extends B>(this: { new (): C; K: f32 }): C, which is a type and not a parameter anything passes, and returns D; super.K, super.f() and super.x name the statics of the class above the one that wrote the member.
A write to a static field through a class that does not declare it (D.K = v, this.K = v, super.K = v), this.#x where this is a class that extends the one declaring #x, this as a value, a static block, and a static declared to return the class that declares it that builds its value with new this(...) where a class inherits it must be refused with the remedy; a write into such a static (D.origin.y = v, a method that changes it) changes the one object both classes read, and a generic base’s statics are its class’s, one for every instance.
규칙 본문과 그 아래 항목은 설계 문서에 적힌 컴파일러 원문이라 한국어 페이지에서도 영어로 둡니다.
근거
a static field that TypeScript code writes is state of the program’s run, which on the GPU is the invocation, so it is the variable a top-level let already is (surface §24); one no code writes folds as a top-level const does; a static block runs when a class is evaluated, and a shader has no such moment. TypeScript keeps statics on the constructor, whose prototype is its base’s constructor, so a read finds the nearest declaration, this in a static member is the constructor the call names, and a write through a derived constructor gives it a property of its own, which one module variable cannot be; a private static lives on its declaring constructor alone, so TypeScript throws where a derived class reaches it through this. TypeScript types a call by the return type the member writes, so a static that returns the class the call names writes that class as its this parameter’s construct signature, and one that writes the declaring class would be that class to the editor and D here (Rule 12.7, proposal 0020).
출처
Rule 6.3; Rule 6.5; ECMAScript ClassDefinitionEvaluation (the constructor’s prototype is the base constructor) and the super keyword; Variable and Value Declarations; surface §24 and §26.
검증 방식
테스트로 확인합니다. 테스트나 게이트 스크립트, CI 워크플로가 이 규칙을 가리키고, 아래 파일 가운데 하나라도 규칙을 더는 가리키지 않으면 추적 검사가 실패합니다.
컴파일러가 이 규칙을 적용하는 곳을 규칙이 직접 적은 내용입니다.
TS8035 CLASS_MEMBER for a static block, for this as a value, for this.#x through a class that extends the one declaring it ("Derived" has no "#k": a private static is the class's own, and TypeScript throws where a body "Derived" inherits reaches it through "this". Name the class that declares it, "Base.#k".) and for super.K = v; TS8005 CONST_ASSIGN for a write to a readonly static and for one through a class that does not declare it ("Derived.count" is a static "Base" declares, and assigning it through "Derived" would give "Derived" a copy of its own in TypeScript. Write "Base.count".); TS8035 CLASS_MEMBER for new this() outside a static member; TS8035 CLASS_MEMBER for a static declared to return the class that declares it that builds its value with new this() where a class inherits it ("Base.make" builds its value with "new this()", so "Derived.make()" returns a Derived, but it is declared to return a Base, which is the type the editor gives the call. Declare the class the call names: static make<C extends Base>(this: { new (): C; SCALE: f32 }): C), pinned with the editor’s half by src/compiler/ts/class-syntax.test.ts; pinned by src/compiler/ts/class-syntax.test.ts and src/compiler/ts/class-methods.test.ts, which also hold the three CPU paths to one value for a static a derived class inherits and for super in a static member; examples/class-builder.shade.ts in the compile gate.
커밋 c66579bf에서 이 규칙을 확인하는 파일입니다. 파일마다 규칙을 처음 가리키는 줄로 연결했습니다.
설명하는 절
커밋 c66579bf의 표면 문서에서 이 규칙을 설명하는 절입니다.
적용하는 오류 코드
규칙이 Enforced by 항목에서 가리키는 진단 코드와, 레지스트리 설명에서 이 규칙을 가리키는 진단 코드입니다.
함께 보기
소스
커밋 c66579bf의 규칙 원문:
docs/language-design.md:745(설계 문서)reqs/rules/RULE-0813.md(추적 항목)