如何在打字稿中返回泛型类型对象的方法?
问题描述:
我想在一个方法应该返回泛型类型的接口。然而当我写:如何在打字稿中返回泛型类型对象的方法?
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
。
如何在接口中键入方法以返回类型为?的通用对象?
答
就这样使用。
export interface Call<T> {
invoke(): T
}
简单的错别字是最难的错字T_T – k0pernikus