class Person {
constructor(public name: string, private _age: number) {}
get age() { return this._age }
set age(v: number) { if (v < 0) throw new Error('age'); this._age = v }
}
Readonly & Parameter Properties
class Point {
constructor(readonly x: number, readonly y: number) {}
}
Inheritance & Abstract
abstract class Shape { abstract area(): number }
class Square extends Shape { constructor(public size: number) { super() } area() { return this.size ** 2 } }
Static members
class Id { static next = 1; static make() { return Id.next++ } }