Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Typescript 无效的等待承诺_Typescript_Request_Request Promise - Fatal编程技术网

Typescript 无效的等待承诺

Typescript 无效的等待承诺,typescript,request,request-promise,Typescript,Request,Request Promise,我有一个TSLint错误,它表示“非承诺值的‘等待’无效”。对于以下行: const response: RequestResponse = <RequestResponse>await this.apiRequest(uri); 既然请求允诺只是扩展了一个允诺,那么是否可以等待它呢?这不起作用的原因是请求允诺使用Bluebird作为允诺库。Tslint在呜咽,因为你在等待蓝鸟的承诺,而不是本地人的承诺 在@types/request promise的顶部,您将找到promise

我有一个TSLint错误,它表示“非承诺值的‘等待’无效”。对于以下行:

const response: RequestResponse = <RequestResponse>await this.apiRequest(uri);

既然请求允诺只是扩展了一个允诺,那么是否可以等待它呢?

这不起作用的原因是请求允诺使用Bluebird作为允诺库。Tslint在呜咽,因为你在等待蓝鸟的承诺,而不是本地人的承诺

@types/request promise
的顶部,您将找到promise override

import Promise=require('bluebird')

为了消除tslint警告,您可以使用本机承诺(request promise native)使用请求库,也可以简单地使用
。然后()
而不是
wait
来等待已解析的响应

private apiRequest: RequestAPI<request.RequestPromise, request.RequestPromiseOptions, RequiredUriUrl>;
this.apiRequest = request.defaults({
      baseUrl: 'https://www.google.com/',
      method: 'GET',
      encoding: 'utf8'
    });
interface RequestPromise extends request.Request, Promise<any> {
      promise(): Promise<any>;
}