我正在尝试在TypeScript中构建类似于MVC的控制器,并且很难获取异步方法来返回延迟的Promise。

这是我的功能签名:

static async GetMatches(input: string, loc?: LatLng):JQueryPromise<any> {


编译器告诉我'JQueryPromise'不是有效的异步函数返回类型。

我本以为这样的东西将是异步函数的最常见用例,但我找不到任何示例。

有什么帮助吗?

最佳答案

JQueryPromise不满足async / await所作承诺的要求,它们应补充以下接口:

interface IPromiseConstructor<T> {
    new (init: (resolve: (value: T | IPromise<T>) => void, reject: (reason: any) => void) => void): IPromise<T>;
}

interface IPromise<T> {
    then<TResult>(onfulfilled: (value: T) => TResult | IPromise<TResult>, onrejected: (reason: any) => TResult | IPromise<TResult>): IPromise<TResult>;
}


有关更多详细信息,请参见第4节“此处的承诺”:link

09-11 14:00