Implementing Multiple Interfaces
What you'll learn: How a single TypeScript class can implement several interfaces at once, ensuring it satisfies all their requirements simultaneously.
The Core Idea
When you need a class to conform to multiple contracts at the same time, TypeScript lets you implement as many interfaces as needed. The class must then provide all properties and methods from every interface it implements. Think of it like a job applicant who needs to meet requirements from multiple departments—they must satisfy all criteria to get hired.
Basic Syntax
You list multiple interfaces after implements, separated by commas:
interface Printable {
print(): void;
}
interface Saveable {
save(): void;
}
class Document implements Printable, Saveable {
print(): void {
console.log("Printing document...");
}
save(): void {
console.log("Saving document...");
}
}
The Document class must have both print() and save() methods. Missing either would cause a compile error.
Why This Matters
Multiple interface implementation allows you to compose behavior requirements. Instead of creating one massive interface, you can combine smaller, focused interfaces that describe specific capabilities. A class that implements both Printable and Saveable clearly communicates: "I can be printed AND saved."
This pattern shines when different parts of your application care about different capabilities of the same object.
Key Takeaway: TypeScript classes can implement multiple interfaces by listing them all after implements, and the compiler enforces that every required member from all interfaces is present in the class.