Created
May 25, 2021 09:31
-
-
Save strboul/6ef31da34dedf9936a105a05f35002b4 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
// We parameterize ApiResponse to specify the type of its data field | |
interface ApiResponse<T> { | |
status: "success" | "failure"; | |
data: T; | |
} | |
interface User { | |
id: number | |
name: string | |
username: string | |
email: string | |
phone: string | |
} | |
const getUsers = async (id: number): Promise<ApiResponse<User[]>> => { | |
const users = await fetch(`https://jsonplaceholder.typicode.com/users/${1}`) | |
return users.json() | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment