When working on my React Native app, I encountered an issue with making an API call and using the json()
method on the result. Here is the code snippet:
await fetch(...)
.catch(e => {...})
.then(res => res.json().then(...)
An error was thrown by TypeScript stating:
Property 'json' does not exist on type 'void | Response'
.
My Query:
- Is there a way to avoid this warning?
- I noticed that swapping the order of
catch
andthen
resolves the error. However, I only wantcatch
to handle errors fromfetch()
, not from the code within thethen
block. Is there a workaround for this?