I am working with an interface or abstract class in TypeScript, and I have numerous classes that implement or extend this interface/class. My goal is to create an array containing the constructors of all these subclasses, while still ensuring that the array's type is defined as the interface/superclass. Is there a way to achieve this?
For example, if I define:
export interface Section {
somePropName: string;
}
or:
export class AbstractSection {
somePropName: string;
}
And then have:
arrayOfClasses: any[] = [
SectionSubclass1,
SectionSubclass2,
SectionSubclass3,
SectionSubclass4,
SectionSubclass5,
];
Is it possible to specify a type for arrayOfClasses
other than just any[]
? Ideally, I would like to be as precise as possible. While in languages like ActionScript you could use Vector.<Class>
, and in Haxe you could use Array<Class>
, in TypeScript it seems more challenging to achieve such specificity.