WIP: infer call
return type based on args
#665
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
👋 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: