expected type of result is
channel<any, Y>
I don't see how you arrived at this conclusion. Following the definition of this class and function:
- The type of
ch
ischannel<void, channel<any, Y>>
(explicitly given)ch#S
=void
ch#Y
=channel<any, Y>
flatMap<R>
returnschannel<Y, R>
when invoked on a achannel<S, Y>
(explicitly given)- For this invocation of
ch.flatMap
,Y
=channel<any, Y>
(from 1.b) - The return type is therefore
channel<channel<any, Y>, R>
(substitute inY
from the definition in 2)
Anyway, because you have an infinitely expanding generic type (see TypeScript spec section 3.8.7), generic type inference is going to be necessarily limited (I believe the problem is actually undecidable). Your best bet in this situation is going to be to specify the type parameter manually, or give the compiler an extra hint by providing a type annotation for x
.