Q33. How does TypeScript type async functions?

An async function always returns a Promise. An annotation such as Promise<User> describes the resolved value as User. Awaiting a promise inside an async function gives access to the resolved value, while errors reject the promise.

A function declared async function getCount(): Promise<number> returns a promise for a number, not a plain number.

Note

Interview approach: define the concept, explain why it matters, then mention one trade-off or limitation.

TypeScript concept
// Illustrative TypeScript contract
type Identifier = string;
const id: Identifier = "item-1";
💡 The example demonstrates the compile-time contract discussed in this question.
Key Takeaways
  • Explain the concept in your own words.
  • Know the practical trade-off and its limits.
  • Use a small example to demonstrate the idea.
Knowledge Check

What is the return type of an async function returning a number?