Guided Notes

Classes & Access Modifiers

Typed class properties, constructors and parameter properties, public/private/protected, readonly, getters/setters, implements, inheritance and abstract classes.

Typed classes

Slide 1 / 4

class BankAccount { readonly id: string; private balance: number = 0;

constructor(id: string, public owner: string) { // parameter property this.id = id; }

deposit(amount: number): void { if (amount <= 0) throw new RangeError("Deposit must be positive"); this.balance += amount; }

get currentBalance(): number { return this.balance; } }

Parameter properties (public owner) declare and assign a property in one step.

← Type Narrowing & Casting