Classes and Access Modifiers
- Typed classes. A TypeScript class declares its fields with types, and constructor parameter modifiers create them in one line.
- private and protected. private hides a member from outside code; protected shares it with subclasses only.
- readonly fields. A readonly field is set once in the constructor and defended by the compiler ever after.
Abstract Classes and Interfaces
- implements. The implements clause checks a class against an interface: the contract verified, not assumed.
- Abstract classes. An abstract class ships shared behaviour plus holes subclasses must fill: half blueprint, half library.
- Interface-first design. Depend on the interface, not the class: callers stay decoupled and tests substitute freely.
Composition and Typed Domain Models
- Composition over inheritance. Composition wires small typed pieces together: deep class trees calcify, assembled parts flex.
- Branded types. A branded type tags a primitive: UserId, not string: so ids of different things stop being interchangeable.
- Making illegal states unrepresentable. Model states so wrong combinations cannot compile: a paid order without a payment simply has no type.
Before and after this level
- Before: Level 6: Advanced Type Transformations: keyof, typeof and Indexed Access, Mapped and Conditional Types, Template Literal Types.
- Next: Level 8: Modules & Projects: Imports and Exports, Module Resolution, Organising Large TypeScript Systems.
In the app each of these ideas is taught and then asked back, and the level ends with a checkpoint and flashcards. See Checkpoints and flashcards.
Frequently asked questions
What does TypeScript Level 7: Classes & Object Design cover?
Classes and Access Modifiers, Abstract Classes and Interfaces, Composition and Typed Domain Models: 3 lessons and 9 ideas.
What should I know before this level?
The level before it, Level 6: Advanced Type Transformations, which covers keyof, typeof and Indexed Access, Mapped and Conditional Types, Template Literal Types.