Extending Abstract Classes in TypeScript
What you'll learn: How subclasses inherit concrete members from abstract classes while being required to implement all abstract members.
The Two-Part Inheritance
When you extend an abstract class, you're receiving two types of members from your parent:
Concrete members are ready-to-use — methods and properties that already have implementations. Your subclass inherits these automatically, just like extending any regular class.
Abstract members are contracts — methods and properties marked with the abstract keyword that your subclass must implement. The compiler will refuse to compile if you forget even one.
How Extension Works
abstract class Animal {
// Concrete property - inherited as-is
name: string;
constructor(name: string) {
this.name = name;
}
// Concrete method - inherited and usable
describe(): string {
return `This is ${this.name}`;
}
// Abstract method - MUST be implemented
abstract makeSound(): string;
}
class Dog extends Animal {
// Must implement makeSound
makeSound(): string {
return "Woof!";
}
// Can use inherited members
greet(): string {
return this.describe() + " and I say " + this.makeSound();
}
}
const dog = new Dog("Buddy");
console.log(dog.describe()); // "This is Buddy" - inherited
console.log(dog.makeSound()); // "Woof!" - implemented
The Implementation Requirement
If you forget to implement an abstract member, TypeScript catches it immediately:
class Cat extends Animal {
// ERROR: Non-abstract class 'Cat' does not implement
// inherited abstract member 'makeSound' from class 'Animal'
}
You must provide implementations for every abstract member. No exceptions, no partial implementations.
Inheriting Multiple Abstract Members
abstract class Vehicle {
protected speed: number = 0;
accelerate(): void {
this.speed += 10;
}
abstract startEngine(): void;
abstract getType(): string;
}
class Car extends Vehicle {
startEngine(): void {
console.log("Engine started");
}
getType(): string {
return "Car";
}
// Inherits accelerate() and speed automatically
}
Key Takeaway: When extending an abstract class, you automatically inherit all concrete members and gain the obligation to implement all abstract members — creating a perfect blend of shared functionality and enforced customization.