Dev.to
7/3/2026

How TypeScript Infers Types Through Async Generators in 2026
Short summary
TypeScript cannot infer the input type parameter (TNext) for async generators because yield expressions receive values bidirectionally from external callers. Developers must explicitly annotate AsyncGenerator<T, TReturn, TNext> to enforce type safety; omitting this creates silent type holes. The paginatedFetch pattern demonstrates the correct approach.
- •Yield expressions are bidirectional—they send values out and receive values back—creating an inference deadlock for TNext types
- •Omitting explicit AsyncGenerator annotations defaults to undefined for TNext, silently accepting any type in .next() calls
- •Use full type annotations to transform type holes into compiler-enforced contracts
Generated with AI, which can make mistakes.
Is this a good recommendation for you?



