如何使用typehint方法返回typescript中的泛型类型对象?

时间:2016-11-04 16:30:14

标签: generics typescript interface

我希望在一个接口中一个方法应该返回泛型类型。然而,当我写道:

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方法返回类型为?

的通用对象

1 个答案:

答案 0 :(得分:1)

就这样使用。

export interface  Call<T> {
    invoke(): T
}