Support conditional types for Generator T / TNext / TReturn #57671
Labels
Awaiting More Feedback
This means we'd like to hear from more people who would be helped by this feature
Suggestion
An idea for TypeScript
π Search Terms
"Generator", "Async Generator", "conditional types", "const" "inference"
β Viability Checklist
β Suggestion
If a generator function is specifically typed to have a conditional relationship between
T
andTNext
then type inference should allow for a type narrowed result according to that conditional type.π Motivating Example
Typescript would be able to support complex type state management (ala redux saga), coroutines (e.g. co) and the interpreter pattern / free monad/applicative.
In the past this was not possible, but given typescript now has
as const
,infer
and conditional types, we should be able to support typed yield result inference in key circumstances.Something like this would be possible:
π» Use Cases
Complex state management and side effects.
For generator functions yielded values are always typed as any. For async generators yielded values are a union of all possible results.
Manually casting
The text was updated successfully, but these errors were encountered: