My issue is very similar to the one mentioned in this thread: Typescript: instance of an abstract class, however, there are some distinctions. If it is indeed a duplicate problem, I would appreciate a clear explanation as I am currently unable to resolve this issue.
I have a Base class:
export abstract class MyBaseClass {
private thing: Thing;
constructor(thing: Thing) {
this.thing = thing;
}
}
export type MyBaseClassType = typeof MyBaseClass;
export interface IMyBaseClass extends MyBaseClassType {};
The challenge arises because MyBaseClass
is part of a library that I am releasing. Users of this library will create a class derived from MyBaseClass
, and the library will serve as an executable solution. They should be able to run their code simply by using the following command:
node our-provided-bin run -b /path/to/client-class-extending-base-class
Within that script, we execute:
const ImportedClassRef: IMyBaseClass = require(resolvedPath);
This ImportedClassRef
variable undergoes several methods before we reach the point where we attempt to instantiate it with:
const dude = new ImportedClassRef(thing);
However, I encounter the error message:
TS2511: Cannot create an instance of an abstract class.