TypeScript · Lesson 49 of 120
Static Members
On the class.
Most properties belong to each object. A static member belongs to the class itself, shared by all. Like a counter of how many orders have been created.

- Per object
- Or per class
- static
Numbering orders
Next ID is static, shared by every order. Each new order takes the next number. We read it through the class name. Run it.
app.tstypescript
class Order {
static nextId = 1042;
readonly id: number;
constructor(public total: number) {
this.id = Order.nextId++;
}
}
const a = new Order(65);
const b = new Order(30);
console.log(a.id, b.id, "| next:", Order.nextId);Output
1042 1043 | next: 1044
Summary
Static members belong to the class, shared by every object. Next, getters and setters.
Key takeaways- static nextId
- Order.nextId
- Shared
Next up: Getters and Setters — computed properties