I’m creating a reusable fetch utility and want the return type to be inferred correctly. How can I handle errors without losing type safety?
async function fetchData<T>(url: string): Promise<T> {
const response = await fetch(url);
return response.json();
}