TypeScript Functions and Narrowing/Type an async function

Return a typed promise from an async function.

Section: Async and Promise Types

Type an async function

typescript
typescript
async function fetchName(): Promise<string> {
  return "Ada";
}
Explanation

Async functions always return a `Promise`, even when returning a plain value.

Learn the surrounding workflow

Compare similar commands or jump into common fixes when this command is part of a bigger troubleshooting path.

Related commands

Same sheet · prioritizing Async and Promise Types
Use `Promise<T>`
Annotate promise-returning APIs explicitly.
OpenIn sheettypescriptsame section
Model a result union
Represent success and failure without throwing.
OpenIn sheettypescriptsame section
Type a function
Annotate parameters and return values.
OpenIn sheettypescript1 tag match
Narrow with `typeof`
Refine primitive unions using runtime checks.
OpenIn sheettypescript1 tag match
Use optional parameters
Mark a parameter as optional with `?`.
OpenIn sheettypescript1 tag match
Narrow with `instanceof`
Refine class-based unions using constructor checks.
OpenIn sheettypescript1 tag match