Skip to content
Home Tutorials Roadmaps Courses Classroom Training Blog
Log in Join free
TypeScript Intermediate Free

Promises & Async/Await

Lesson 17 of 17 · Async TypeScript 100%

TypeScript works with Promises and async/await for asynchronous operations.

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();

You reached the end

You finished the TypeScript tutorial!

Take a full course for real projects and a verifiable certificate.