-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Creating Generic Slices #286
Comments
At the moment, I'm sorry to say this is simply impossible without copy-pasting code from the type definitions and mimicking the current generics construct. I've spent the whole day yesterday trying to find a general simpler alternative to that generics construct, but to no avail. I believe there just is none. I'll try to find something that will at least satisfy those restrictions you're running into sometime this weekend. If I get this to work you'll be able to do it like in https://codesandbox.io/s/dreamy-elion-5dnr8 (this is just a mock-up, I need to figure out what works as |
As an alternative, I've had success defining a base type for the data and reusable reducers that work with that type, and then "manually" calling |
I was afraid of this.
This was actually my first approach (but I used the
No need to spend any more time on this! It's the holidays after all :) We can stick with generic reducers and maybe revisit this in the future. Converting our older pieces of the store to Thanks for your time! |
I won't guarantee I'll spend too much on it but this bugs me enough that I want to give it at least another try ^^ |
@MarceloAlves I've got a Draft PR over in #290 - if that lands, you could do it like this: I guess that would solve your use case? |
I think this will work perfectly! I'll give it a shot. Thanks so much for taking the time!! |
Yep, and that's out in https://github.com/reduxjs/redux-toolkit/releases/tag/v1.2.0 . |
Hi @markerikson Back to work, got everything updated and it looks to be working out great. Should I close this issue? |
Yeah, looks like this has been resolved. Glad this is working! |
Stemming from this thread
For better or worse a lot of our state has the same structure and so I'm trying to create helper where we can pass a
name
, theinitialState
and end up with a slice that contains most of everything we need.I'm running into some issues with how to type it correctly. I'm pretty green to more advanced types so this could all be me not understanding how to type it. An example of what I'm trying to achieve:
The issues I end up with:
When using this new
createSlice
and trying to pass it more reducers:This error happens:
When using actions:
This error occurs:
All this to say, I'm stuck. Not sure if I'm missing some pretty obvious things but any help would be greatly appreciated!
The text was updated successfully, but these errors were encountered: