Given this hierarhcy class
export class A { static m() { return 'a'}; } export class B extends A { static m() { return 'b'}; } export class C extends A { static m() { return 'c'}; }
I need a method that takes an array of classes (not an instance), extends A and calls m() for each element of the array:
function looper(classes: A[]) { classes.forEach(c => cm()); }
This expects an array of instances of A or its subclasses.
How can I get a method that takes as classes of arguments that extend A?
Generics as directed by @Oscar Paz
EDIT 1
In addition, the input to the looper must be stored in the property of the object:
export class Container { public klazzes: A[]; }
I
source share