Looking for a way to determine the type that declares a static method. This needs to be functional even with subclasses.
class Animal {
static getType(): any {
// Want to return the declaring type of this method,
// For example, Animal in this case.
// Should also work for subclasses like Dog, Cat, etc.
// Attempted...
// return this.prototype; // But unsuccessful.
}
}
class Dog extends Animal {
}
class Cat extends Animal {
}
When getType()
is called on Animal
, Dog
, and Cat
, it should output:
Animal.getType() // Animal
Dog.getType() // Dog
Cat.getType() // Cat
Unsure if this can be achieved, but any guidance is appreciated!
Additionally, looking to utilize getType()
to retrieve the declaring type, enabling iteration over other static members of that type, similar to:
Object.keys(Dog) // ["Poodle", "Labrador", "Husky"]