Class incorrectly implements interface
A class that claims to implement an interface is missing one or more of the properties or methods required by that interface.
- 1Forgetting to implement a method defined in the interface.
- 2A typo in the name of an implemented property or method.
- 3The signature of the implemented method does not match the signature in the interface (e.g., different parameters or return type).
A class implements an interface but is missing a required method.
interface Person {
name: string;
greet(): void;
}
class Employee implements Person {
name: string = "John";
// Missing greet() method
}expected output
error TS2415: Class 'Employee' incorrectly implements interface 'Person'. Property 'greet' is missing in type 'Employee' but required in type 'Person'.
Fix 1
Implement the missing member
WHEN A required property or method is not present.
interface Person {
name: string;
greet(): void;
}
class Employee implements Person {
name: string = "John";
greet() {
console.log("Hello");
}
}Why this works
Adding the missing members to the class fulfills the interface contract.
Fix 2
Correct the member signature
WHEN The implementation does not match the interface definition.
interface Person {
name: string;
greet(message: string): void;
}
class Employee implements Person {
name: string = "John";
greet(message: string) {
console.log(message);
}
}Why this works
Aligning the method's parameters and return type with the interface.
✕ Remove the 'implements' clause
This silences the error but loses the explicit contract that ensures the class adheres to the interface's shape.
microsoft/TypeScript src/compiler/diagnosticMessages.json
Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev