Classes and enums
Classes with typed fields and access modifiers, inheritance, abstract classes and implements, and enums and as const.
About 4 hours of study
Learning objectives
- Write classes with private state
- Use inheritance and interfaces for polymorphism
- Choose between enums and literal unions
Lessons
- 1
Classes in TypeScript Intermediate
Typed fields and constructors, parameter properties, public, private, protected and #private members, readonly fields, getters and setters, and static members.
- 2
Inheritance, abstract classes and implements Intermediate
Extending classes with extends and super, overriding methods, protected members, abstract classes that leave methods to subclasses, and classes that implement interfaces.
- 3
Enums, as const and literal types Intermediate
Numeric and string enums, what an enum becomes at run time, as const for read-only literal data, and deriving union types from constant arrays and objects with typeof and keyof.
Module practice
- TypeScript: A bank account classEasy
- TypeScript: A temperature class with getters and settersMedium
- TypeScript: A matrix classHard
- TypeScript: Payroll with an abstract classEasy
- TypeScript: Notifiers behind one interfaceMedium
- TypeScript: A fleet of vehiclesHard
- TypeScript: Days of the week with an enumEasy
- TypeScript: Filter logs by levelMedium
- TypeScript: An order state machineHard