I encountered a TSLint error stating "Invalid 'await' of a non-Promise value." in the line of code below:
const response: RequestResponse = <RequestResponse>await this.apiRequest(uri);
Additional code context:
private apiRequest: RequestAPI<request.RequestPromise, request.RequestPromiseOptions, RequiredUriUrl>;
this.apiRequest = request.defaults({
baseUrl: 'https://www.google.com/',
method: 'GET',
encoding: 'utf8'
});
Based on the Type definitions, the return type for this.apiRequest(uri)
is request.RequestPromise
. The definition of RequestPromise
from the @types/request-promise library is as follows:
interface RequestPromise extends request.Request, Promise<any> {
promise(): Promise<any>;
}
Shouldn't it be feasible to await the RequestPromise given that it extends a Promise?