question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Make createActionCreator simpler by removing `resolve` callback from executor

See original GitHub issue

From 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:open
  • Created 4 years ago
  • Comments:16 (16 by maintainers)

github_iconTop GitHub Comments

4reactions
the-dr-lazycommented, Dec 16, 2019
Type '{ type: string; payload: string; }' is not assignable to type '"{ payload?: any, meta?: any }"'.
2reactions
the-dr-lazycommented, Sep 11, 2019

I clicked “close issue” button by mistake. 😄

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found