v5.0.0-beta.0 #4553
markerikson
started this conversation in
General
v5.0.0-beta.0
#4553
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
This beta release alters our TS types to add and use a new
UnknownActiontype where possible for better type safety, and includes all prior changes from the 5.0 alphas. This release has breaking changes from 4.x.We recommend that users should prefer using Redux Toolkit for Redux development, and use the RTK 2.0 beta that depends on this core release, rather than using the Redux core library directly
Changelog
New
UnknownActionTypeThe Redux 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 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 changes from the earlier
5.0-alphareleases:createStoredeprecation tag portedisMinifiedcheckSetReducertype accepts aPreloadedStategenericactionandnextare typed asunknownaction.typefield must be a stringWhat's Changed
Full Changelog: v5.0.0-alpha.6...v5.0.0-beta.0
This discussion was created from the release v5.0.0-beta.0.
Beta Was this translation helpful? Give feedback.
All reactions