- Error
- Reported by the type checker
TS2341
Property '{0}' is private and only accessible within class '{1}'.
A `private` member is used outside the class that declares it. Use a public method, or change its visibility.
What it means
A member marked private can only be used inside its own class body, not in subclasses or other code.
Example
class Account {
private balance = 0;
}
export const b = new Account().balance;
ts-r-check -p tsconfig.json --pretty false ts-r outputindex.ts(5,32): error TS2341: Property 'balance' is private and only accessible within class 'Account'.
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
- Use a public method or getter that exposes what you need.
- Make the member
protected(subclasses) or public if outside code should use it.