The TypeScript compiler has an error on the last line:
function handler(num: number): Generator<number, void, unknown>
Argument of type '(num: number) => Generator<number, void, unknown>' is not assignable to parameter of type '(item: unknown) => any'.
Types of parameters 'num' and 'item' are incompatible.
Type 'unknown' is not assignable to type 'number'.ts(2345)
By making the type for the saga's params inferred as a generic type parameter and passing that through to SagaType as a type parameter, the compiler infers them correctly and the error is resolved.
This makes a small tweak to how the parameters for a saga given to
expectSaga
ortestSaga
are inferred.This snippet does not work with the latest version, 4.0.4 and TypeScript 4.6
The TypeScript compiler has an error on the last line:
By making the type for the saga's params inferred as a generic type parameter and passing that through to
SagaType
as a type parameter, the compiler infers them correctly and the error is resolved.