Skip to main content
Module 4 · Lesson 1 of 27/22 in the course~16 min
Module lessons (1/2)

Classes and Modifiers

Lesson preview6 hands-on exercises readyCourse TypeScript · Module 4 — Utility Classes and Types

Encapsulate state with public, private, protected, readonly, parameter properties, and implements.

What you'll learn in this lesson

  • Control encapsulation with the public, private, protected, and readonly modifiers.
  • Reduce the boilerplate using the parameter properties in the constructor (constructor(public readonly id: number)).
  • Enforce contracts via implements and define non-instantiable base schemas with abstract class.
  • Distinguish TypeScript static private from ECMAScript native #privati fields at runtime.

Overview

TypeScript brings comprehensive static checks to JavaScript classes: compile-time checked visibility modifiers, immutable fields with readonly, abstract classes, and verified implementation of interfaces (implements).

Writing a modifier (public, private, protected, or readonly) directly in front of a parameter of the constructor declares the property and automatically executes this.prop = prop.

Sections covered in this lesson

  1. 1Modifiers and Parameter Properties
  2. 2implements, Inheritance and Classes abstract
  3. 3Guided practice
  4. 4Check for understanding
Pro Lesson · Module 4 — Utility Classes and Types

Unlock "Classes and Modifiers" and the full Course TypeScript curriculum

Encapsulate state with public, private, protected, readonly, parameter properties, and implements.

Unlock all 6 hands-on exercises in this lesson plus every advanced WebAssembly module with automated checks.

  • Instant access to all advanced modules in Course TypeScript plus 17 more courses
  • Hands-on browser exercises with automated test suites and solutions
  • 14-day money-back guarantee processed via Paddle.com

14-day guarantee · Cancel anytimeModule 1, all 18 interactive games, and cheatsheets are always free.