Classes get full typing: access modifiers, readonly fields, implements contracts, and abstract bases. Prefer interfaces for shape contracts; classes add runtime behavior.
class Service implements Disposable { constructor(private url: string) {} }interface Printable { print(): void; }
abstract class Shape {
constructor(protected color: string) {}
abstract area(): number;
}
class Rectangle extends Shape implements Printable {
constructor(color: string, private width: number, private height: number) {
super(color);
}
area() {
return this.width * this.height;
}
print() {
console.log(`Rect ${this.color}: ${this.area()}`);
}
}
const rect = new Rectangle("blue", 10, 4);
rect.print();Understanding Classes & OOP is fundamental to mastering TypeScript. Practice with the examples above and experiment with variations to solidify your knowledge.