Make createActionCreator simpler by removing `resolve` callback from executor
See original GitHub issueFrom TypeScript 3.0 we are able to infer function’s parameters with their names. So now we can remove resolve callback from executor in createActionCreator to make the API simpler.
Example:
// (name: string) => { type: "FETCH_TODOS"; }
createActionCreator("FETCH_TODOS");
// (name: string) => { type: "ADD_TODO"; payload: string; }
createActionCreator("ADD_TODO", (name: string) => ({ payload: name }));
There is one caveat point that has been encountered in #108 and that’s type property in return type of callable (2nd argument of proposed createActionCreator). One possible solution for the mentioned problem which I think is ideal is to set the type of type property to undefiend.
// Types of property 'type' are incompatible.
// Type 'string' is not assignable to type 'undefined'.ts(2345)
createActionCreator("ADD_TODO", (name: string) => ({ type: 'MISTAKE', payload: name }));
We can call the callable’s return type TypelessAction as it’s type should be undefined.
Issue Analytics
- State:
- Created 4 years ago
- Comments:16 (16 by maintainers)
Top Results From Across the Web
createActionCreator(type[, executor])
executor (Function ): a function that gives an argument named resolve that gives payload and meta as optional arguments and returns an action....
Read more >Resolve promise after callback it's executed
I have the following code on which I am trying to block the execution of the method _saveAddress multiple time, so I made...
Read more >deox
Make createActionCreator simpler by removing `resolve` callback from executor · How it will lead with react-hooks? · prev state vs next state.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

I clicked “close issue” button by mistake. 😄