Created
December 17, 2021 22:47
-
-
Save akihisa-shimada/d6e890ec3112d6ed97b4a4ce4bff3167 to your computer and use it in GitHub Desktop.
This file contains 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 characters
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