I want to in an interface that a method should return the generic type . Yet when I write:
export interface Call<T> {
invoke(): <T>
}
I get the error: ( Expected
.
I had before typehinted methods to return a Promise<T>
and it worked:
export interface Call<T> {
invoke(): Promise<T> // no error here, yet I do not want to return a promise of <T>
}
I then tried to:
export interface Call<T> {
invoke(): Object<T>
}
yet this leads to: Type Object is not generic
.
How to typehint method in an interface to return generic object of type ?
Just use like this.
export interface Call<T> {
invoke(): T
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.