agiledigital / typed-redux-saga

An attempt to bring better TypeScript typing to redux-saga.
MIT License
315 stars 33 forks source link

Typing for `all` forces homogenous values #523

Open jjoekoullas opened 3 years ago

jjoekoullas commented 3 years ago

all assumes a shared type between arguments, causing the type inference to devolve to any for types that don't share a more refined base type.

Promise.all handles this well, if via a bit of a hack: all<T1, T2>(values: readonly [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>]): Promise<[T1, T2]>;

I believe typed-redux-saga could do something similar -

export type All<
    T1 extends (...args: any[]) => any,
    T2 extends (...args: any[]) => any
> =
    (toRun: [SagaGenerator<SagaReturnType<T1>>, SagaGenerator<SagaReturnType<T2>>])
    => SagaGenerator<[SagaReturnType<T1>, SagaReturnType<T2>]>

essentially it'd be nice if all just converted from [generator<T>, generator<T1>,...etc] into generator<[T, T1]>

I'd like to submit a PR for this, however I'm having trouble understanding the original signature for all - specifically the second argument for the returned SagaGenerator<EffectReturnType<T>[], AllEffect<T>>. What is that second parameter for? I imagine it will need to change (perhaps in redux-saga) to support this.