I have the following example:
class Parent {
foo() {
console.log("foo");
}
}
class Child1 extends Parent {
bar() {
this.foo();
console.log("bar");
}
}
class Child2 extends Parent {
baz() {
this.foo();
console.log("baz");
}
}
const Children = [Child1, Child2];
function someFunc<C>(children: C[]) { // ???
const _children = {}; // ???
for (let c of children) {
const _c = new c();
_children[c.name] = _c;
}
return _children;
}
const instances = someFunc(Children); // ???
instances.Child1.bar();
How can I tell the someFunc
method that its going to be expecting an array of Classes of type Children? What do I need to pass as a Generic argument to someFunc
?
Mostly so it will know that instances.Child1
has a method called bar()