TypeScript works with Promises and async/await for asynchronous operations.
Getting Started
What is TypeScript?
Basic Types
Types & Interfaces
Async TypeScript
Promises & Async/Await
TypeScript
Intermediate
FREE
Promises & Async/Await
Lesson 1 of 17
Intermediate
Interactive
Syntax
TYPESCRIPT
async function fetchData(): Promise<Data> { const response = await fetch("/api/data"); return response.json(); }
Promises and Async/Await
TYPESCRIPT
function fetchData(): Promise<string> { return new Promise((resolve) => { setTimeout(() => resolve("Data loaded"), 1000); }); } async function getData(): Promise<void> { console.log("Loading..."); let result = await fetchData(); console.log(result); console.log("Done!"); } getData();