- Error
- Reported by the type checker
TS18013
Property '{0}' is not accessible outside class '{1}' because it has a private identifier.
A `#private` class member is used outside the class that declares it. Use it inside the class, or expose a method.
What it means
Members whose names start with # are private at runtime and in the type system: only code inside the class body that declares them can read or write them. Accessing one from outside (including from a subclass) is reported with this code.
Example
class Counter {
#count = 0;
}
export function peek(c: Counter) {
return c.#count;
}
ts-r-check -p tsconfig.json --pretty false ts-r outputindex.ts(5,12): error TS18013: Property '#count' is not accessible outside class 'Counter' because it has a private identifier.
Recorded by node scripts/verify-examples.mjs with ts-r built from commit 6deaf01. The example uses the default tsconfig: strict, target: es2022, module: esnext, moduleResolution: bundler.
How to fix
- Move the code that needs the member into the class.
- Add a public method or getter that returns what callers need.