Classes in TypeScript
From the TypeScript cheat sheet ยท Interfaces & Classes ยท verified Jul 2026
Classes
Object-oriented programming with TypeScript classes
typescript
// Basic class
class Person {
name: string
age: number
constructor(name: string, age: number) {
this.name = name
this.age = age
}
greet(): string {
return `Hello, I'm ${this.name}`
}
}
// Access modifiers
class Employee {
public name: string
private salary: number
protected department: string
readonly id: number
constructor(name: string, salary: number) {
this.name = name
this.salary = salary
this.id = Math.random()
}
}๐ก Use parameter properties to reduce boilerplate
๐ Private fields start with # in modern TS
๐ Abstract classes cannot be instantiated