TypeScript Async & Promises

Type asynchronous code.

✍️ 3 exercises + code challenge in this lesson

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.

Key Takeaways: TypeScript Async & Promises

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.

TypeScript Async & Promises Code Example

TypeScript
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();
Output
Laptop: Rs 185,000
Free sign-in required · Google login available

TypeScript Async & Promises Practice Exercises

Check what you learned in “TypeScript Async & Promises”.

/ 3 solved
Fill in the blank

Type an async function that resolves to a string.

async function load():  { return "done"; }
✓ Correct! Not quite. Try again.
Multiple choice

What does an async function return?

✓ Correct! Not quite. Try again.
Code challenge

Write async function getNumber(): Promise<number> that returns 7, then await it and log the result.

Write the code in the live editor. Your answer is checked automatically.

Free sign-in required · Google login available

to save your exercise progress.
Finished this lesson?
Mark it complete to track your progress.

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