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

Lessons

  1. 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. 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. 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

Module quiz

1. What does constructor(private name: string) {} do?
2. Which private members are hidden at run time?
3. What is Direction.Left in enum Direction { Up, Down, Left, Right }?
4. Why can't you write new Shape() when Shape is abstract?
5. What does keyof typeof PRICES give for a constant object PRICES?
6. Why mark an overriding method with override?

‹ Shaping dataGeneric code ›