You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@angelsl keep in mind that the documentation is not written with TS in mind, so differences between what is possible when using plain JS and what is possible by default when using TS are somewhat expected. For instance, it's possible to just yield anything - for example a number, but types shouldn't quite allow this because it doesn't make much sense. There is little to no gain in using yield* over yield fork() and in general the latter is recommended.
I get that the documentation is not written for TS in mind, but I still think this is an error in the typings. For what it's worth, I just ran into a case where I needed to use yield* in a saga.
I have same problem. As a temporary solution I have created this type which use Generator from lib.es2015.generator.d.ts. type ExpandableSaga<Args extends any[] = any[], R = void> = (...args: Args) => Generator<StrictEffect, R, any>;
It is combination of Saga and SagaIterator types. In most cases my saga does not return any value, that is why return type is set to void by default.
Generator type contains [Symbol.iterator](): Generator<T, TReturn, TNext>; so it can be used with yield*.
The documentation suggests that we can
yield*
a Saga to compose them.However, this isn't possible in TS 3.6+ if the yielded Saga is annotated as
SagaIterator
: https://codesandbox.io/s/dry-forest-gni5eThis is the type error:
For TS <= 3.5, this type definition is used, which makes it possible:
But for TS >= 3.6, this is used instead, which is no longer Iterable:
One can do this instead:
But it is not strictly the same.
Is the type definition wrong, or is the documentation wrong, or is this just a limitation due to the stricter generator checking in TS 3.6?
The text was updated successfully, but these errors were encountered: