Which fix removes the bug?
async function total(): Promise<number> {
const res = fetch('/api/sum');
return (await res).ok ? 1 : 0;
}
- Await at the call:
await fetch('/api/sum') - Await at the call:
async fetch('/api/sum') - Drop
asyncfrom the function signature - Change the return type to
Promise<void>
Await the promise where it is created so
Play Problem Solving ▸
res is the response, not a pending promise.