Last active
February 24, 2023 13:39
-
-
Save lihaibh/448aa7032c8c684b4e83f1bbcfc37475 to your computer and use it in GitHub Desktop.
Get return type of a function
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 characters
async function getItems() { | |
const requestTime = new Date(); | |
const response = await fetch('http://myservice/items'); | |
const items = (await response.json()) as { id: string; price: number }[]; | |
const responseTime = new Date(); | |
return { | |
items, | |
requestTime, | |
responseTime, | |
}; | |
} | |
type ItemsResponse = Awaited<ReturnType<typeof getItems>>; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment