Module lessons (1/2)
Classes and Modifiers
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, andreadonlymodifiers. - Reduce the boilerplate using the parameter properties in the constructor (
constructor(public readonly id: number)). - Enforce contracts via
implementsand define non-instantiable base schemas withabstract class. - Distinguish TypeScript static
privatefrom ECMAScript native#privatifields 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
- 1Modifiers and Parameter Properties
- 2
implements, Inheritance and Classesabstract - 3Guided practice
- 4Check for understanding
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.