In order to create a new instance of a base abstract class that implements an interface, I have the interface, the base class, and some properties in an Angular component. Surprisingly, no errors are thrown in the browser (perhaps due to JavaScript's forgiving nature), but TSLint raises the following error:
TS2511:Cannot create an instance of the abstract class KitCustomizationBase
If the abstract
keyword is removed, the error disappears. According to the TypeScript documentation, abstract classes can contain implemented logic. Can someone clarify this for me?
Here is my interface:
export interface KitCustomizationInterface {
items: number[];
indexes: number[];
counter: number;
}
This is my base class (the same error occurs even without the constructor):
import { KitCustomizationInterface } from '...';
export abstract class KitCustomizationBase implements KitCustomizationInterface {
public items: number[];
public indexes: number[];
public counter: number;
constructor(items: number[], indexes: number[], counter: number) {
this.items = items;
this.indexes = indexes;
this.counter = counter;
}
}
And here is the code snippet from my component:
...
let k: KitCustomizationBase = new KitCustomizationBase([], [], 0);
...
Update
Regarding the duplicate markers:
- Angular and TypeScript handle interfaces differently.
- This specific TSLint error doesn't yield relevant results in Google search.
- The provided link by the duplicate markers does not offer a precise answer, rather suggesting to refer to the documentation. But which documentation exactly?