Skip to content

Classes & Advanced OOP

Almost everything else in this course is a type — a compile-time construct that gets erased. A class is different: it is one of the rare declarations that creates both a type and a value. The class name is a type you can annotate with, and simultaneously a runtime constructor you can call with new.

class User {
constructor(public name: string) {}
}
const u: User = new User("Ada"); // `User` as a TYPE (annotation) and a VALUE (constructor)

That dual nature is why classes feel special, and why their features split into two groups: ones the compiler checks and erases (like private), and ones that survive into the emitted JavaScript (like #private fields).

LessonWhat you’ll learn
Classes, deepAccess modifiers, readonly, parameter properties, static, abstract, implements
this types & polymorphismPolymorphic this, this parameters, and binding pitfalls in the type system
DecoratorsThe modern stage-3 decorators — class, method, field — and factories
Mixins & compositionBuilding behavior from composable class factories instead of deep hierarchies

TypeScript supports classical extends inheritance, but this module leans toward the features the community actually reaches for in modern code: composition over inheritance. Deep class hierarchies are brittle; this types, decorators, and mixins let you build flexible, reusable behavior without them.

flowchart TB
  cls["class declaration"] --> typeworld["TYPE world
(erased): private, protected,
implements, abstract"]
  cls --> valueworld["VALUE world
(runtime): #private, static,
the constructor, methods"]
The two kinds of class features
What makes a class special compared to a type alias or interface?
Which class feature survives into the emitted JavaScript?
What design approach does modern TypeScript OOP tend to favor?