규칙 8.16
8장, 함수와 진입점 테스트
An instance field that holds an arrow function or a function expression is a method of its class under the field’s name: the function’s parameters, return type and body are the method’s, an expression body is the value it returns, and this in it is the object, as it is in TypeScript.
With no return type written, it returns what its body does, and an expression body that is an assignment, ++ or -- runs as a statement (Rule 8.19).
A static field that holds a function, a function with type parameters, and an async or generator function must be refused with the remedy.
A member a class that extends declares again must keep the kind the class above gives it, as TypeScript requires (a field, a method or an accessor, a field that holds a function standing where a method was and a field where an abstract accessor was), and super.f on a field that holds a function must be refused; so must an accessor over an abstract field, which TypeScript takes and which a struct here cannot mean.
규칙 본문과 그 아래 항목은 설계 문서에 적힌 컴파일러 원문이라 한국어 페이지에서도 영어로 둡니다.
근거
onHit = (d: f32): f32 => d * this.k is how TypeScript code often writes a method, to keep this bound; a shader has no function value to hand anywhere, so the one thing such a field can be is the method it is written as, called as o.onHit(d), and this is the object in both.
A static one binds this to the class that declares it where a static method binds it to the class the call names (Rule 8.13), so it is written as the static method it means; type parameters need a generic function.
TypeScript refuses a member that changes kind in a class that extends, and without the check each such program compiled to the derived class’s member where TypeScript’s object holds the base’s; a field is the object’s own, so super does not reach one.
An abstract field is laid out in every struct below the class that declares it, so a body that class wrote reads the member and never an accessor a class below declares, 0 where TypeScript computes the getter; abstract get f(): T says the same thing and reaches the accessor.
출처
ECMAScript class field definitions and arrow functions (this is the object the field initializer runs for); TypeScript’s override checks (TS2416, TS2423, TS2425, TS2426, TS2610, TS2611) and TS2855 (super on a field); Rule 8.9; Rule 8.13; surface §26.
검증 방식
테스트로 확인합니다. 테스트나 게이트 스크립트, CI 워크플로가 이 규칙을 가리키고, 아래 파일 가운데 하나라도 규칙을 더는 가리키지 않으면 추적 검사가 실패합니다.
컴파일러가 이 규칙을 적용하는 곳을 규칙이 직접 적은 내용입니다.
TS8035 CLASS_MEMBER for each refusal (A static field holding a function is a static method: write "static f(...) { ... }".; "B.f" is a method, and the "A.f" it overrides is a field that holds a function; TypeScript refuses an override of another kind. Declare it as a field that holds a function, or rename it.; "super.f" names a field that holds a function, and a field is the object's own, which "super" does not reach. Declare "A.f" as a method, or write "this.f".), 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 field that holds a function, an override of one, and a method a field overrides; examples/class-parts.shade.ts in the compile gate.
커밋 c66579bf에서 이 규칙을 확인하는 파일입니다. 파일마다 규칙을 처음 가리키는 줄로 연결했습니다.
설명하는 절
커밋 c66579bf의 표면 문서에서 이 규칙을 설명하는 절입니다.
적용하는 오류 코드
규칙이 Enforced by 항목에서 가리키는 진단 코드와, 레지스트리 설명에서 이 규칙을 가리키는 진단 코드입니다.
함께 보기
소스
커밋 c66579bf의 규칙 원문:
docs/language-design.md:771(설계 문서)reqs/rules/RULE-0816.md(추적 항목)