Inheritance in TypeScript

From the TypeScript cheat sheet · Interfaces & Classes · verified Jul 2026

Inheritance

Class inheritance and method overriding in TypeScript

typescript
// Basic inheritance
class Animal {
  name: string
  
  constructor(name: string) {
    this.name = name
  }
  
  move(distance: number = 0): void {
    console.log(`${this.name} moved ${distance}m`)
  }
}

class Dog extends Animal {
  bark(): void {
    console.log("Woof! Woof!")
  }
}

// Method overriding
class Cat extends Animal {
  move(distance: number = 5): void {
    console.log("Cat prowling...")
    super.move(distance)
  }
}
💡 Use super() to call parent constructor
📌 Protected members accessible in derived classes
✅ Mixins provide multiple inheritance pattern

More TypeScript tasks

Back to the full TypeScript cheat sheet