What types does TypeScript give this async code, and which line is an error?
Name the type each ^? line points at, and every error TypeScript reports.
async function loadUser(id: number) { if (id < 0) throw new Error("Invalid id"); return { id, name: "Ada" };} const pending = loadUser(1);// ^?type User = Awaited<ReturnType<typeof loadUser>>;// ^? async function showUser() { const [user, total] = await Promise.all([loadUser(1), Promise.resolve(3)]); // ^? const name: string = loadUser(2).name; loadUser(-1).catch((reason) => console.log(reason.message)); // ^?}Work it out first: the compiler shows every error and type.
The answer
Work out every error TypeScript reports and every type it shows, line by line. Then check.
Checking your sign-in…