fetchJson<T>(url) compiles, but it lies about T. Rewrite it so the type is backed by a runtime check.
Every caller can write fetchJson<User>("/api/user") and get a Promise<User>, whatever the server sends. Change the signature so a value can only be typed T after code has checked it, and make a failed response (such as a 404) reject instead of being parsed.
async function fetchJson<T>(url: string): Promise<T> { const response = await fetch(url); return response.json();} // type User = { id: number; name: string };// const user = await fetchJson<User>("/api/user");// // compiles, but nothing checks that the server sent a UserThe answer
Write it yourself first. Then compare it with a reference solution and the checks it passes.
Checking your sign-in…