79200629

Date: 2024-11-18 16:10:11
Score: 0.5
Natty:
Report link

Well, it depends on if you are trying to create an array of the constructors or of objects?

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

Reasons:
  • Blacklisted phrase (1): stackoverflow
  • Whitelisted phrase (-2): solution:
  • RegEx Blacklisted phrase (1): I want
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Contains question mark (0.5):
  • Low reputation (1):
Posted by: Eli