Skip to content

Instantly share code, notes, and snippets.

@akihisa-shimada
Created December 17, 2021 22:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save akihisa-shimada/d6e890ec3112d6ed97b4a4ce4bff3167 to your computer and use it in GitHub Desktop.
Save akihisa-shimada/d6e890ec3112d6ed97b4a4ce4bff3167 to your computer and use it in GitHub Desktop.
const fetcher = async<T>(url: string): Promise<T> => {
const res = await fetch(url).then<T>(res => res.json());
return res;
}
export const getUser = async(): Promise<{id: number, name: string}> => {
const user = await fetcher<{id: number, name: string}>('https://example.com/api/user');
return user;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment