---
title: "Rule 8.15: Functions and entry points in TypeShade"
description: "Rule 8.15 of the TypeShade language design, in Functions and entry points."
url: https://typeshade.dev/reference/rules/8-15/
language: en
---

# Rule 8.15

Chapter 8, Functions and entry points Test

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](https://typeshade.dev/reference/rules/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](https://typeshade.dev/reference/rules/8-12/)).

The rule text and the parts under it are the compiler's own English, as the design document writes them.

## Rationale

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

## Derives from

TypeScript’s [member visibility](https://www.typescriptlang.org/docs/handbook/2/classes.html#member-visibility) (TS2341, TS2445, TS2446; TS2322 for a literal of such a class); [Rule 8.12](https://typeshade.dev/reference/rules/8-12/); surface §26.

## How it is verified

Checked by a test. A test, a gate script or a CI workflow names this rule, and the traceability check fails when a file listed below stops naming it.

Where the rule says the compiler enforces it:

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

The files that verify it at commit af54ddad5, each at the first line that names the rule:

- [`src/compiler/ts/class-syntax.test.ts:1143`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/class-syntax.test.ts#L1143)

## Explained in

The sections of the surface document that explain this rule, at commit af54ddad5:

- [§26 Classes with methods, a constructor and static functions](https://github.com/typeshade/typeshade/blob/af54ddad5/docs/use-typeshade-surface.md#26-classes-with-methods-a-constructor-and-static-functions)

## Error codes that enforce it

The diagnostic codes the rule names under Enforced by, or whose registry text names the rule:

**[`TS8010`](https://typeshade.dev/reference/errors/ts8010/) `STRUCT_FIELD`**

An invalid struct field or declaration shape. A class with no fields is accepted; this code covers an invalid field declaration, an empty struct that is not a class, an `@align` on a field, which is not applied, and a user-defined value whose uses give it two locations ([Rule 6.6](https://typeshade.dev/reference/rules/6-6/)).

**[`TS8035`](https://typeshade.dev/reference/errors/ts8035/) `CLASS_MEMBER`**

A class member shape that the surface does not take, a use of a member that the class rules refuse, or a `new` that builds no class ([Rule 8.13](https://typeshade.dev/reference/rules/8-13/)). Getters and setters, static fields and methods, overload signatures, abstract members, `#` private names and methods that change their object all compile. The message names the member or the target and the edit.

## See also

- [Rule 8.14](https://typeshade.dev/reference/rules/8-14/) Test
- [Rule 8.16](https://typeshade.dev/reference/rules/8-16/) Test
- [Rule 8.9](https://typeshade.dev/reference/rules/8-9/)
- [Rule 8.12](https://typeshade.dev/reference/rules/8-12/)
- [Design rules](https://typeshade.dev/reference/rules/)
- [Error codes](https://typeshade.dev/reference/errors/)

## Source

The rule at commit af54ddad5:

- [`docs/language-design.md:964`](https://github.com/typeshade/typeshade/blob/af54ddad5/docs/language-design.md#L964) (the design document)
- [`reqs/rules/RULE-0815.md`](https://github.com/typeshade/typeshade/blob/af54ddad5/reqs/rules/RULE-0815.md) (its traceability item)
