I am currently working on developing a generic function that calls another function with an any
type parameter. Here is what I have attempted:
static GetInstance<T>(): T {
return <T>injector.get(T); // get(param: any): any
}
The issue is that this code does not compile successfully. I am encountering the error message Cannot find name 'T'
.
I experimented with get(typeof T)
, but it seems that typeof T returns a string value of "function"
.
What steps can I take to resolve this problem?
To clarify, the get() method accepts types as parameters. Here is an example of how you can use it:
import { MyService } from '..'
constructor(){
let val = this.injector.get(MyService);
}