I have a fetch call which is async of course, but I like to wrap all that in one or more functions, so the calling function doesn't bother.
This is what I have right now:
private async wrapFetch(url): Promise<void> {
this.responseText = await this.doFetch(url);
}
private async doFetch(url): Promise<string> {
return fetch(url)
.then((rsp: response) => {
return rsp.text();
});
}
Now, I would like to call wrapFetch as if it is a normal async function
this.wrapFetch('some-url');
But, this line gives the following warning:
Promise returned from wrapFetch is ignored
I've tried to change the return type from wrapFetch, but that made it worse. Any suggestions how I can fix this or should I
wrapFetchmethod, if you are inisde anasyncfunction a simpleawaitbefore the call should be enough, if not you should probably add acatchhandler to avoid any silent errorsconsole.log('f')is still beforeconsole.log('e'). Is there a way to fix this, without usingasync/awaitinside thedoItfunction ?asyncand add theawaitkeyword before method calls (in thedoItmethod for instance...) event if you don't care about the result, just for the control flow, added them in the example stackblitz.com/edit/typescript-1iqahc?file=index.ts