Well, it depends on if you are trying to create an array of the constructors or of objects?
Handler
as {new (): Base}
. This is type of a constructor.Derived
in the object of type OneNode
, write new Derived()
.Working code:
// Now I want to collect the derived classes in an array...
interface OneNode {
handler: { new (): Base };
}
const availableNodes: OneNode[] = [{ handler: Derived }];
// ...and instantiate some of them only when needed
const y = new (availableNodes[0]?.handler)();
y.fun();
Source for a list of constructors solution: https://stackoverflow.com/a/13408029/2834938