$ ./guess_the_languageProblem Solving — fix the bug
Problem Solving — fix the bug · medium · #60

Which fix removes the bug?

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