- Error
- Reported by the type checker
TS2511
Cannot create an instance of an abstract class.
new is used on an abstract class. Instantiate a concrete subclass instead.
What it means
An abstract class can have members without implementations, so it can't be constructed directly. Only non-abstract subclasses can be created with new.
Example
abstract class Shape {
abstract area(): number;
}
export const s = new Shape();
ts-r-check -p tsconfig.json --pretty false ts-r outputindex.ts(4,18): error TS2511: Cannot create an instance of an abstract class.
Recorded by node scripts/verify-examples.mjs with ts-r built from commit 6deaf01. The example uses the default tsconfig: strict, target: es2022, module: esnext, moduleResolution: bundler.
How to fix
- Create an instance of a concrete subclass that implements the abstract members.
- Remove
abstractfrom the class if it is complete and meant to be instantiated.