我希望在一个接口中一个方法应该返回泛型类型。然而,当我写道:
export interface Call<T> {
invoke(): <T>
}
我收到错误:( Expected
。
我之前使用了typehinted方法来返回Promise<T>
并且它有效:
export interface Call<T> {
invoke(): Promise<T> // no error here, yet I do not want to return a promise of <T>
}
然后我试着:
export interface Call<T> {
invoke(): Object<T>
}
然而这导致:Type Object is not generic
。
如何在接口中使用typehint方法返回类型为?
的通用对象答案 0 :(得分:1)
就这样使用。
export interface Call<T> {
invoke(): T
}