Skip to content
Guest
Learn TypeScript · Course Syllabus Show lessons
Production TypeScript · 8 min read · Intermediate

Classes, Access Modifiers & Parameter Properties

Write concise TypeScript classes using public, private, protected, readonly, and implements.

What you'll learn

  • Use constructor parameter properties (`private readonly id: string`) to cut boilerplate
  • Enforce class contracts with `implements Interface`
  • Distinguish compile-time `private` from runtime `#private` fields

TypeScript parameter properties let you declare and assign a class field directly inside the constructor signature (constructor(private readonly name: string)), saving lines of repetitive boilerplate.

Fill-in-the-Blank Exercise

Class Implementing an Interface

Make MemoryStore implement Store and declare items as private.

interface Store { count(): number; }

class MemoryStore  Store {
 items: string[] = [];
count() { return this.items.length; }
}

Live Code Lab

TypeScriptclasses.ts
Expected OutputClick “Run Live” to compile with TypeScript 5.6
TypeScript: 94%

Check Your Understanding

Score: 0 / 1

1. What does `constructor(private readonly id: string)` do in TypeScript?

Study Workspace

Finished this lesson?

Your progress is saved locally in your browser, no account needed.

Search courses, lessons, and references

Type to search across all courses, lessons, and quick references.

Press Esc to close Powered by Pagefind