-
-
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
Action creators from createSlice
are not inferred as PayloadActionCreator
#157
Comments
/cc @denisw, @Jessidhia, @Dudeonyx , @phryneas : any ideas? |
I just tried specifically hand-editing the typings for export declare type SliceActionCreator<P> = P extends void ? PayloadActionCreator<void> : PayloadActionCreator<P>; And that seems to compile okay. |
Those two ActionCreators seem to have diverged on the zero-argument-case - even though they actually are exactly the same internally. I guess I'll try to make those behave similarly when I touch them for #149 anyways :) |
Meh. I tried to poke around at this some myself right now, but don't have time since I'm at work. What I'm seeing is that my suggested change breaks the expected test failure in // typings:expect-error
counter.actions.multiply() Which I think is verifying that if the reducer is defined as not taking an action arg, that the action creator rejects attempts to call it without an argument. I also added this test, which fails without with the change but passes with it: const incrementType = counter.actions.increment.type @phryneas, could you do me a favor and try to resolve just this one issue for now and pick up with the payload customization thing later? |
I guess adding this behaviour to the
Sure thing :) |
Fixed via #158 . |
I'm finally getting a chance to use RSK myself in a real project, and I just ran into an interesting issue.
In
createAction()
, we specifically attach the generated type to the generated action creator so that we can use the action creator itself as the type value, by both overridingtoString()
and adding it asactionCreator.type = type
.I've got some code I just wrote that looks like:
So, even though we're using
createAction()
inside ofcreateSlice
, there's a disconnect in the types.In our TS code, we specifically have a
PayloadActionCreator
type that appears to define itself as "a function with this payload, plus thetype
field".However, I don't see that
PayloadActionCreator
type being used increateSlice
anywhere. Instead, there's aSliceActionCreator
type that reuses thePayloadAction
definition.Seems like
SliceActionCreator
ought to be referring toPayloadActionCreator
somehow?The text was updated successfully, but these errors were encountered: