-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
infer action creators from createSlice
as PayloadActionCreator
#158
Conversation
Deploy preview for redux-starter-kit-docs ready! Built with commit a960dc6 https://deploy-preview-158--redux-starter-kit-docs.netlify.com |
I vote that |
} | ||
}) | ||
|
||
const x: "increment" = counter.actions.increment.type; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are these not "counter/increment"
? That's really confusing to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch.
Because I typed them wrongly and those tests only check for types at compile time, not validate that it is the real output.
That said, I'll have to remove that and only type the type
as string then - can't do concatenation with types :(
One other question to throw out there. If we do eventually tack on |
I'm all for that. 👍 |
PS: Generally, I'm for a renaming, but having changed it to FSA everywhere in the code, it looks really more like a generic than a type to me, with it being only capital letters. Not really sure if that would be good for readablility. Do we have other options? I was thinking along the lines of:
But reading all those above, I have to say that I'd also be fine with keeping PayloadAction and just adding a third parameter for |
Eh, let's keep |
Cool. All right, let's get this out. Thank you so much for working on this! |
Happy to help 😎 Just because I noticed, in case you forgot (I don't know your release workflow): While the 0.6 is available on npm, the commit & tag are still missing on GitHub. Did you forget to push? |
Not quite. I actually did the release from work, but I'm behind a corporate proxy. I use https://github.com/sindresorhus/np to do my releases, but it seems that doesn't work great behind proxies. It was able to hit NPM to publish, but not do the Github work. I'll get those up tonight after I get home. |
see #157
This changes the createSlice types to use PayloadActionCreator and modifies the behaviour of PayloadActionCreator to account for
P = void
andP = Something | undefined
.Here are some examples:
so payload types are now interfered much more accurate, which is especially useful for the
<any>
case.There is one open question open regarding the typing of the
undefined
argument: ifundefined
is not omitted, but explicitly specified, should we return an Action or a PayloadAction? (See https://github.com/reduxjs/redux-starter-kit/pull/158/files#diff-437575fb1d5c39e3edd424ab38899f8eR27 )PS: I could easily do away with the excessive type interference, but that would hurt the
<any>
case a bit in my eyes and I think it won't hurt, so I'm looking forward to your opinion on it ;)