👋 big fan of this project! One issue I've run into is invoking functions will call where the return type is dependent on arguments passed. For example, an identity function is likely the simplest example:
const identity = <T>(x: T): T => x;
// $ExpectType "foo"
identity("foo" as const);
However, this currently fails when using call. The root case seems come from the SagaReturnType helper from @redux-saga/core:
export type SagaReturnType<S extends Function> =
S extends (...args: any[]) => SagaIterator<infer RT> ? RT :
S extends (...args: any[]) => Promise<infer RT> ? RT :
S extends (...args: any[]) => infer RT ? RT :
never;
Inferring a return type without knowing the arguments used for invocation will cause TypeScript to evaluate this as unknown for some functions.
Fortunately, the arguments can be considered. This PR proposes a new type for call:
This works great for simple use cases like call(fn, ...args), though I'm struggling to implement it for all other call signatures of call. I've committed an attempt at fixing call([context, fnName], ...args) with a failing test, though I'm not sure exactly where it's falling apart. Opening a PR to get some thoughts and hopefully arrive at a good solution for all call signatures!
👋 big fan of this project! One issue I've run into is invoking functions will
call
where the return type is dependent on arguments passed. For example, an identity function is likely the simplest example:However, this currently fails when using
call
. The root case seems come from theSagaReturnType
helper from@redux-saga/core
:Inferring a return type without knowing the arguments used for invocation will cause TypeScript to evaluate this as
unknown
for some functions.Fortunately, the arguments can be considered. This PR proposes a new type for
call
:To handle
Return
potentially being aSagaIterator
orPromise
, I've created a newExtractReturnValue
helper similar toSagaReturnType
:This works great for simple use cases like
call(fn, ...args)
, though I'm struggling to implement it for all other call signatures ofcall
. I've committed an attempt at fixingcall([context, fnName], ...args)
with a failing test, though I'm not sure exactly where it's falling apart. Opening a PR to get some thoughts and hopefully arrive at a good solution for all call signatures!Related issues: