Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

TypeScript · Interface

AsyncGenerator

AsyncGenerator is the iterator type produced by an async generator function. It yields values asynchronously and exposes promise-based iteration operations.

How it works

AsyncGenerator describes the object returned by an async generator function. Its methods asynchronously report iteration results through Promises, while the generic parameters represent yielded values, the final return value, and values accepted by next().

Syntax

interface AsyncGenerator<T = unknown, TReturn = any, TNext = unknown> extends AsyncIterator<T, TReturn, TNext> {}

Returns

An AsyncGenerator object that asynchronously produces iteration results.

Key points

  • AsyncGenerator belongs to the async-iteration model and follows the iterator pattern.
  • Its iteration-control methods are asynchronous because they return promises.
  • An async generator can forward iteration to synchronous or asynchronous iterable sources with yield*.
  • Async generators combine asynchronous function behavior with incremental value production.
  • Async iteration requires the object to expose the Symbol.asyncIterator protocol.

Common mistakes

  • Async generator syntax cannot be written as an arrow function; use a declaration, expression, or method instead.
  • The runtime must provide Promise support, and async iteration also needs Symbol.asyncIterator support.
  • A for-await-of loop must run inside an async function or async generator.

Example: Async generator producing numbers

async function* numbers(): AsyncGenerator<number, void, unknown> {
  yield 1;
  yield 2;
}

for await (const number of numbers()) {
  console.log(number);
}

The async generator produces values that can be consumed asynchronously with for await...of.

When to use it

Streaming asynchronous data

Read paginated or streamed data without loading all results at once.

Progressive computation

Expose incremental results from an asynchronous computation.

Async iterable pipelines

Consume asynchronous sources with standard iteration syntax.

Interview questions

QWhat does AsyncGenerator represent?

AsyncGenerator is the iterator type produced by an async generator. Unlike a synchronous iterator, its next, return, and throw operations produce promises for iteration results.

Follow-up: How does it differ from AsyncIterator? AsyncGenerator is the specialized interface for generator-produced async iterators and includes generator behavior in addition to asynchronous iteration.

QWhat do AsyncGenerator's generic parameters mean?

Its type parameters describe the yielded value, the generator's eventual return value, and the value accepted by next(). A declaration such as AsyncGenerator<number, void, unknown> yields numbers, returns void, and accepts an unknown input.

Follow-up: Why use unknown for the third parameter? It safely represents an input whose type is not constrained by the generator implementation.

QHow is an async generator consumed?

An async generator is declared with async function*. It can yield partial results over time, and consumers can process those results with for await...of.

Follow-up: Can async generators delegate with yield*? Yes; the documentation says delegation can target either an iterable or an async iterable.

  • AsyncIterator
  • IteratorResult
  • Symbol.asyncIterator
  • for..await..of

Source: Documentation - TypeScript 2.3. Checked 2026-10-15.