microsoft / microsoft/TypeScript

`forEachChild` is hard to use with async API

Offen
#64,126 0 Kommentare 0 Reaktionen 1 zugewiesene Person Auf GitHub ansehen

@andrewbranch arbeitet bereits daran.

Seit 01.9.2026.

Domain: API
Vorherrschende Sprache
Go
Sterne
111k
Forks
14.3k
Ø Merge
2 T. 4 Std.
Gemergte PRs (30 T.)
132

Beschreibung

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.

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.