Comments (7)
@chmac Can you also attach a block of code where you define actionCreator
?
from redux-saga-promise-actions.
@tomekkleszcz Yep, sorry, original example wasn't clear at all, I updated it. The actionCreator
as it was is a PromiseAction.request. I've added that to make it clearer.
from redux-saga-promise-actions.
@chmac I don't use redux-typed-saga
in my projects. I've checked out this library and this is a declaration for putResolve
function:
export function putResolve<A extends Action>(
action: A,
): SagaGenerator<A, PutEffect<A>>;
As you can see the return value typed as the action which is provided as the argument of the putResolve
function which in your case totally incorrect - you provide actionCreators.request()
and you would expect the return value to be {token: 'string'}
, but it is the type of the action you provide instead.
There are three solutions to this problem:
- Use
putResolve
fromredux-saga
- Update
dispatch
helper in my library to type the return type correctly - Create a PR to
typed-redux-saga
and fix the problem
I advise you to use the first solution for now. As soon as I close other feature requests I think I may start to work on updating dispatch
helper.
from redux-saga-promise-actions.
@tomekkleszcz Thanks for taking the time to look at this for me, I appreciate it.
I started out using putResolve()
from redux-saga, but in that case I get the type of val
as unknown
. The trick typed-redux-saga
uses is to use yield*
instead of yield
and then a babel macro to transform the whole thing at runtime. As I understand it, the issue is that TypeScript has no way of knowing what that the Redux Saga middleware will resolve into the yield
call.
I also tried the dispatch
helper from your package, again I get type unknown
for val
.
Do you have an example of how I could use putResolve
from redux-saga
, or preferably, your dispatch
function and have TypeScript know what the type of val
will be? That would be the best case, I could drop the typed-redux-saga
package altogether.
from redux-saga-promise-actions.
I think in your case the following solution would work:
import {putResolve} from 'redux-saga'
const actionCreators = createPromiseAction(
"foo/request",
"foo/success",
"foo/failure"
)<undefined, { token: "string" }, { error: Error }>();
function* saga() {
const val: { token: "string" } = yield putResolve(actionCreators.request());
}
from redux-saga-promise-actions.
@tomekkleszcz Yeah, I can typecast the return value. But if I get the type wrong, there's no checking. That's the aim of the typed-redux-saga
package, to avoid that potential mistake.
OK, thanks a lot for all the input. I'll try digging further into the putResolve
types from redux-typed-saga
, it's definitely not an issue in your package. I actually get the correct type, just that the putResolve()
type definition in typed-redux-saga
doesn't understand that it should take the ResolveType
and not the whole thing.
Thanks again for the help on this. 👍 👍 👍
from redux-saga-promise-actions.
@tomekkleszcz Looking at this fresh today, I realise that I think the typing in the typed-redux-saga (and not the redux-typed-saga) package is wrong for putResolve()
. I opened an issue. Thanks again for the help, closing this as it's not an issue in this package I realise.
from redux-saga-promise-actions.
Related Issues (14)
- Feature Request: Add a dispatch effect HOT 2
- Example app
- Create JSDoc annotations
- Error running build HOT 4
- Having trouble typing resolvePromiseAction() HOT 3
- Typed putResolve snippet that might be helpful HOT 3
- Add a prepare/transformer option
- Proper types for `dispatch` HOT 1
- redux-saga-promise-actions show error
- how to use the resolvePromiseAction(action, response)?
- Feature Request: Add a generic try / catch saga wrapper HOT 17
- Typescript as a devDependency? HOT 3
- Dispatch type returns TResolveType rather than Promise<TResolveType>
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from redux-saga-promise-actions.