I have a selection of classes structured like this:
abstract class A {}
class AB extends A {}
class AC extends A {}
class AD extends A {}
In one of my files, I need to create an export that maps class names to their constructors, for example:
export default {
AB,
AC,
AD
};
What type should this export be?
I attempted the following:
type Mappings = {
[typeName: string]: typeof A
};
However, when I use it like this:
import mappings from '..';
let s: string;
const TypeName = mappings[s];
const pr = new TypeName(); // ERROR
An error occurs stating:
Cannot create an instance of an abstract class
since A is an abstract class.
My goal is to understand how to replace typeof A
with something like subtypeof A
or any other suitable option.