Given the following code:
class Type
{
static Property = 10;
}
class Type1 extends Type
{
static Property = 20;
}
class Type2 extends Type
{
static Property = 30;
}
I would like to make a function that can return an array of types that all inherit from the same base, that allows access to the "static side" of the class. For example:
function GetTypes(): typeof Type[]
{
return [Type1, Type2];
}
So now ideally I could go:
GetTypes(0).Property; // Equal to 20
However it doesn't seem like there is syntax for storing multiple typeof types in an array.
Is this correct?
Of course there is. Your code is correct minus the return type of the GetTypes
function. (To be clear Steve's answer would solve your issue as well, this is just another approach without making use of interfaces).
Change the return type of the GetTypes
function to:
function GetTypes(): Array<typeof Type>
{
return [Type1, Type2];
}
This should to the trick.