Created
March 31, 2023 14:23
-
-
Save ugultopu/e8cd1b44eef9b0c8192199fc7c2fb2db to your computer and use it in GitHub Desktop.
Revisions
-
ugultopu created this gist
Mar 31, 2023 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,17 @@ If you wished that you had the ability of declaring the response body's types for your [`fetch`](https://developer.mozilla.org/en-US/docs/Web/API/fetch) calls beforehand (where you made the call), you can use the following `fetch` wrapper: ```typescript 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](https://www.npmjs.com/package/ts-generic-fetch).