Can someone please assist me in understanding how to pass the typeof XXX
to a method parameter and specify that the return type should be an instance of that method?
Here is the method I am working with:
public getComponent<T>(component: typeof Behavior): Parameters<(c: T) => T> {}
This is how I am trying to use it:
class Main {
getComponent() {
// Finds an instance and returns it
}
}
class Behavior {}
class Item extends Behavior {}
let result = (new Main()).getComponent(Item)
In my TypeScript code, the variable result
ends up being an instance of Behavior
instead of Item
. Could someone please guide me on the correct approach to ensure that the result is an instance of Item
?