Skip to content

Instantly share code, notes, and snippets.

@lihaibh
Last active February 24, 2023 13:39
Show Gist options
  • Save lihaibh/448aa7032c8c684b4e83f1bbcfc37475 to your computer and use it in GitHub Desktop.
Save lihaibh/448aa7032c8c684b4e83f1bbcfc37475 to your computer and use it in GitHub Desktop.
Get return type of a function
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