v2.0.0-beta.0 #3493
Replies: 4 comments 20 replies
-
|
RTK 2 is looking really good! Looking forward to the final release. Small question: Why was Dictionary removed? Found it quite handy. I can of course inline it in the app, but was wondering if it was considered harmful in any way. |
Beta Was this translation helpful? Give feedback.
-
|
When I run |
Beta Was this translation helpful? Give feedback.
-
|
I'm trying to add middleware to the default middleware like this (using typescript): Everything works as expected, however i'm getting a typescript error for Should I be using Tuple for this? |
Beta Was this translation helpful? Give feedback.
-
|
I came up with this 1 year ago :)) Glad it is going to be supported in the main library and I don't have to maintain the codebase for long :D These were my junk takes on this matter: Hopefully the extrareducers can merge as well. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
This beta release updates many of our TS types for improved type safety and behavior, updates
entityAdapter.getSelectors()to accept acreateSelectoroption, depends on the latest[email protected]release, and includes all prior changes from the 2.0 alphas. This release has breaking changes.Changelog
Store Configuration Tweaks and Type Safety
We've seen many cases where users passing the
middlewareparameter toconfigureStorehave tried spreading the array returned bygetDefaultMiddleware(), or passed an alternate plain array. This unfortunately loses the exact TS types from the individual middleware, and often causes TS problems down the road (such asdispatchbeing typed asDispatch<AnyAction>and not knowing about thunks).getDefaultMiddleware()already used an internalMiddlewareArrayclass, anArraysubclass that had strongly typed.concat/prepend()methods to correctly capture and retain the middleware types.We've renamed that type to
Tuple, andconfigureStore's TS types now require that you must useTupleif you want to pass your own array of middleware:(Note that this has no effect if you're using RTK with plain JS, and you could still pass a plain array here.)
Similarly, the
enhancersfield used to accept an array directly. It now is a callback that receives agetDefaultEnhancersmethod, equivalent togetDefaultMiddleware():It too expects a
Tuplereturn value if you're using TS.Entity Adapter Updates
entityAdapter.getSelectors()now accepts an options object as its second argument. This allows you to pass in your own preferredcreateSelectormethod, which will be used to memoize the generated selectors. This could be useful if you want to use one of Reselect's new alternate memoizers, or some other memoization library with an equivalent signature.createEntityAdapternow accepts anIdgeneric argument, which will be used to strongly type the item IDs anywhere those are exposed.The
.entitieslookup table is now defined to use a standard TSRecord<Id, MyEntityType>, which assumes that each item lookup exists by default. Previously, it used aDictionary<MyEntityType>type, which assumed the result wasMyEntityType | undefined. TheDictionarytype has been removed.If you prefer to assume that the lookups might be undefined, use TypeScript's
noUncheckedIndexedAccessconfiguration option to control that.New
UnknownActionTypeThe Redux core TS types have always exported an
AnyActiontype, which is defined to have{type: string}and treat any other field asany. This makes it easy to write uses likeconsole.log(action.whatever), but unfortunately does not provide any meaningful type safety.We now export an
UnknownActiontype, which treats all fields other thanaction.typeasunknown. This encourages users to write type guards that check the action object and assert its specific TS type. Inside of those checks, you can access a field with better type safety.UnknownActionis now the default any place in the Redux and RTK source that expects an action object.AnyActionstill exists for compatibility, but has been marked as deprecated.Note that Redux Toolkit's action creators have a
.match()method that acts as a useful type guard:Earlier Alpha Changes
Summarizing the changes from earlier alphas:
New Features
combineSlicesAPI with built-in support for slice reducer injection for code-splittingselectorsfield increateSlicecreateSlice.reducers, which allows defining thunks insidecreateSliceconfigureStoreaddsautoBatchEnhancerby defaultBreaking Changes
createReducerandcreateSlice.extraReducershas been removed5.0-betaactionCreator.toString()override removed (although we're reconsidering this)getDefaultMiddlewareremovedWhat's Changed
createSelectorinstance to adapter.getSelectors by @EskiMojo14 in Allow passing acreateSelectorinstance to adapter.getSelectors #3481Full Changelog: v2.0.0-alpha.6...v2.0.0-beta.0
This discussion was created from the release v2.0.0-beta.0.
Beta Was this translation helpful? Give feedback.
All reactions