What Does implements Do in TypeScript?
In TypeScript, the implements keyword is used to force a class to conform to an interface.
This means the class must implement all properties and methods described in the interface. Otherwise TypeScript will throw a compilation error.
Syntax
interface IAnimal {
name: string;
makeSound(): void;
}
class Dog implements IAnimal {
name: string;
constructor(name: string) {
this.name = name;
}
makeSound() {
console.log("Woof!");
}
}
What happens?
- Class
Dogmust implement all properties and methods of interfaceIAnimal. - If at least one is missing — TypeScript will show an error.
Error Example
interface Person {
name: string;
age: number;
}
class User implements Person {
name: string;
// Error: Property 'age' is missing
}
implements with multiple interfaces
Can implement multiple interfaces separated by commas:
interface A {
a(): void;
}
interface B {
b(): void;
}
class C implements A, B {
a() {
console.log("A");
}
b() {
console.log("B");
}
}
Why use implements?
- For structure control of class
- For API documentation: it's clear what class should support
- For architectural compliance guarantees
- For modularity and reusability: one interface — many implementations
Important:
implements works only at type level. In compiled JavaScript there are no interfaces.