규칙 8.15
이 페이지에서

규칙 8.15

8장, 함수와 진입점 테스트

A member declared private may be named only inside the body of the class that declares it, and one declared protected only inside the bodies of that class and of the classes that extend it, on an object of the naming body’s own class or of one that extends it; a name either rule does not allow must be refused with the remedy. The declaration a name is checked against is the one the class whose body holds it sees, whichever class that body is compiled for (Rule 8.9), and a field a derived class declares again without a modifier is public, as TypeScript allows. An object literal cannot build a class with a private or protected field, and a spread and a destructuring pattern leave such a field out, as they leave out a private name (Rule 8.12).

규칙 본문과 그 아래 항목은 설계 문서에 적힌 컴파일러 원문이라 한국어 페이지에서도 영어로 둡니다.

근거

private and protected are TypeScript’s own access rules, and the front end does not run the checker that enforces them, so without this a program TypeScript refuses would compile; before this rule the two keywords were accepted and meant nothing.

출처

TypeScript’s member visibility (TS2341, TS2445, TS2446; TS2322 for a literal of such a class); Rule 8.12; surface §26.

검증 방식

테스트로 확인합니다. 테스트나 게이트 스크립트, CI 워크플로가 이 규칙을 가리키고, 아래 파일 가운데 하나라도 규칙을 더는 가리키지 않으면 추적 검사가 실패합니다.

컴파일러가 이 규칙을 적용하는 곳을 규칙이 직접 적은 내용입니다.

TS8035 CLASS_MEMBER for each refusal ("C.x" is private, so only the body of "C" may name it. Reach it through a public member of "C".; "C.p" is protected, and "D" may name it only on a "D"; this object is a "C". Reach it through a public member of "C".), TS8010 STRUCT_FIELD for an object literal of such a class, pinned by src/compiler/ts/class-syntax.test.ts.

커밋 c66579bf에서 이 규칙을 확인하는 파일입니다. 파일마다 규칙을 처음 가리키는 줄로 연결했습니다.

설명하는 절

커밋 c66579bf의 표면 문서에서 이 규칙을 설명하는 절입니다.

적용하는 오류 코드

규칙이 Enforced by 항목에서 가리키는 진단 코드와, 레지스트리 설명에서 이 규칙을 가리키는 진단 코드입니다.

TS8010 STRUCT_FIELD
An invalid struct field or declaration shape.
TS8035 CLASS_MEMBER
A class member shape the surface does not take, or a use of a member the class rules refuse, and a new that builds no class (Rule 8.13).

함께 보기

소스

커밋 c66579bf의 규칙 원문:

이 페이지 편집 문제 보고