microsoft / microsoft/TypeScript
`forEachChild` is hard to use with async API
@andrewbranch ci sta già lavorando.
Dal 1/9/2026.
- Lingua principale
- Go
- Stelle
- 111k
- Fork
- 14.3k
- Merge medio
- 2g 4h
- PR unite (30g)
- 132
Descrizione
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.
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Valutazione
Questa issue non è ancora stata valutata.