If you wished that you had the ability of declaring the response body's types for your fetch calls beforehand (where you made the call), you can use the following fetch wrapper:
interface GenericResponse<T> extends Response {
clone(): GenericResponse<T>;
json(): Promise<T>;
}
export default async function genericFetch<T>(
input: RequestInfo | URL,
init?: RequestInit
) {
return fetch(input, init) as Promise<GenericResponse<T>>;
}Inspired by ts-generic-fetch.