TypeScript · Classes and modules

Access modifiers

Controls compile-time visibility. ECMAScript #private fields provide real runtime privacy.

Syntax
public / private / protected

Example

Example
class Counter {
  private count = 0;
  increment() { return ++this.count; }
}

More in this group

abstract class Class Declaration file implements Namespace import readonly field Type-only import

Learn this in the course

Reference pages are the quick answer. The course explains the why, shows the full example and ends with a challenge.

Open the course