microsoft / microsoft/TypeScript

`forEachChild` is hard to use with async API

Open
#64,126 0 comments 0 reactions 1 assignee View on GitHub

@andrewbranch is already working on this.

Since Sep 1, 2026.

Domain: API
Dominant language
Go
Stars
111k
Forks
14.3k
Avg merge
2d 4h
Merged PRs (30d)
132

Description

If you try to use the async API, it's a challenge today. The API provides a synchronous tree traversal function (`forEachChild`), but pulling on semantic information is asynchronous.

The problem isn't the mixture itself - it's that `forEachChild` stops walking when the visitor function returns a truthy result. This makes it impractical to use with async APIs because every async function returns a `Promise` which is truthy.

The current workarounds are a little awkward, basically introducing a layer of indirection between the traversal function and `forEachChild` that uses intermediate queues.

I'm not sure if there's an ideal solution - there's at least two problems right now:

- it feels like we could benefit from a `forEachChildAsync` or something like that.
- using `forEachChild` is a foot-gun if you've decided to use the async API.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.