Async and await

The async keyword indicates that a function returns a Promise.

If the return type is not specified, TypeScript will attempt to infer the type of the returned Promise. If the function is missing type specifications, the return type will default to Promise<any>, or Promise<void> if the function does not return anything.

Asynchronous function
async function getResultAsync(): Promise<any> { ... }

One of the key advantages to using Promises is the ability to use async and await.

Loading TypeScript...

async functions

An async function must return a correctly-typed Promise object.

Loading TypeScript...

Was this page helpful?