我有一个 TSLint 错误,上面写着“非 Promise 值的'await' 无效”。对于以下行:
const response: RequestResponse = <RequestResponse>await this.apiRequest(uri);
上下文代码:
private apiRequest: RequestAPI<request.RequestPromise, request.RequestPromiseOptions, RequiredUriUrl>;
this.apiRequest = request.defaults({
baseUrl: 'https://www.google.com/',
method: 'GET',
encoding: 'utf8'
});
根据类型定义,返回类型this.apiRequest(uri)
为request.RequestPromise
。RequestPromise
在 @types/request-promise 库中再次定义如下:
interface RequestPromise extends request.Request, Promise<any> {
promise(): Promise<any>;
}
难道不应该等待 RequestPromise ,因为它只是扩展了一个 Promise 吗?