Docs
/
TypeScript
Chapter 10

10 — Classes & Access Modifiers

Core Concepts

  • public — accessible from anywhere (default)
  • private — accessible only within the class
  • protected — accessible within the class and subclasses
  • readonly — can only be set in constructor or declaration
  • abstract classes — can't be instantiated, define contracts for subclasses
  • implements — class must satisfy an interface
  • static members — belong to the class, not instances
  • Parameter properties — shorthand constructor constructor(public name: string)
  • ES2022 #private — true runtime private fields (vs TS private which is compile-time only)

Access Modifier Summary

ModifierClassSubclassOutside
publicYesYesYes
protectedYesYesNo
privateYesNoNo
#fieldYesNoNo (runtime enforced)