Multiple Interface Implementation
What you'll learn: How a single class can implement multiple interfaces at once to satisfy different sets of requirements.
The Core Idea
In TypeScript, a class can implement more than one interface by listing them with commas. The class must then provide all properties and methods required by every interface it claims to implement. Think of it like earning multiple certifications — to claim you have them all, you need to meet the requirements of each one individually.
Multiple Interfaces Syntax
interface Flyable {
fly(): void;
altitude: number;
}
interface Swimmable {
swim(): void;
depth: number;
}
class Duck implements Flyable, Swimmable {
altitude: number = 0;
depth: number = 0;
fly(): void {
console.log("Duck is flying");
}
swim(): void {
console.log("Duck is swimming");
}
}
The Duck class must satisfy both Flyable and Swimmable. If you forget any property or method from either interface, TypeScript will report an error.
Why This Matters
Multiple interface implementation lets you model objects with multiple capabilities without creating complex inheritance chains. A Duck can both fly and swim, a Phone might be both Rechargeable and Networkable, and a User might be both Authenticatable and Serializable.
This approach keeps your code flexible — you can mix and match capabilities as needed, and functions can accept parameters based on specific interfaces rather than entire class hierarchies.
Key Takeaway: A class can implement multiple interfaces by listing them separated by commas, and TypeScript enforces that all constraints from all interfaces are satisfied.