An async function returns Promise<T>, where T is the type of the resolved value:
async function getUser(): Promise<User> { ... }
Type API responses with interfaces so the rest of your code knows the shape of the data.
Type asynchronous code.
✍️ 3 exercises + code challenge in this lessonAn async function returns Promise<T>, where T is the type of the resolved value:
async function getUser(): Promise<User> { ... }
Type API responses with interfaces so the rest of your code knows the shape of the data.
Mastering TypeScript Async & Promises helps you write clean and reliable TypeScript code. Follow standard conventions, test edge cases, and keep logic simple. Try running the code example below and complete the exercises to build confidence.
interface Product {
name: string;
price: number;
}
function fetchProduct(): Promise<Product> {
return new Promise(resolve => setTimeout(() => resolve({ name: "Laptop", price: 185000 }), 100));
}
async function main(): Promise<void> {
const p = await fetchProduct();
console.log(`${p.name}: Rs ${p.price.toLocaleString("en-US")}`);
}
main();
Laptop: Rs 185,000
Check what you learned in “TypeScript Async & Promises”.
Type an async function that resolves to a string.
async function load(): { return "done"; }
What does an async function return?
Write async function getNumber(): Promise<number> that returns 7, then await it and log the result.
Free sign-in required · Google login available
Stuck on something?
Ask the community in the CodesInTech forum.
Need a developer?
Learning on your own is great — and when you need professional help, our team builds custom software, websites and mobile apps for clients worldwide.
Explore Our Services