TypeScript error TS2515 is reported when a concrete (non-abstract) class extends an abstract class but does not implement all of its abstract members. Abstract members define the interface that subclasses must fulfill.
Why it happens
- •A subclass is missing an implementation of one or more abstract methods.
- •A method was added to the abstract class but not yet added to all subclasses.
- •Copy-pasting a class definition without updating the abstract implementations.
- •Renaming an abstract method without updating the subclass override.
Examples
Code that triggers the error
abstract class Shape {
abstract area(): number;
}
class Circle extends Shape {
// forgot to implement area()
}Error output
error TS2515: Non-abstract class 'Circle' does not implement inherited abstract member 'area' from class 'Shape'.
How to fix it
Implement all abstract methods in your concrete class. Your IDE will usually show which methods are missing. When adding a new abstract method to a base class, TypeScript will immediately flag all subclasses that need updating.
Fixed code
abstract class Shape {
abstract area(): number;
}
class Circle extends Shape {
constructor(private radius: number) {
super();
}
area(): number {
return Math.PI * this.radius ** 2;
}
}Related errors
Ready to practice your English at work?
Lingua-e has interactive exercises built around real developer conversations: standups, code reviews, retrospectives, and more. Practice until it comes naturally.
Try Lingua-e for free