Tsallaka zuwa abun ciki
Justice Tech School

Async, Promises and Modules

async functions return Promise<T>. Use await inside them. Modules use import and export, and type-only imports are erased at build time.

Example
async function fetchScore(id: number): Promise<number> {
  await new Promise((r) => setTimeout(r, 10));
  return id * 10;
}
async function main() {
  const results = await Promise.all([fetchScore(1), fetchScore(2)]);
  console.log(results);
}
main();

Result

[ 10, 20 ]

Exercise

Wait for a promise.

const v =  fetchScore(1);

Quiz Test

What does an async function return?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.