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
-
This beta release alters our TS types to add and use a new
UnknownAction
type 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
UnknownAction
TypeThe Redux TS types have always exported an
AnyAction
type, 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
UnknownAction
type, which treats all fields other thanaction.type
asunknown
. 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.UnknownAction
is now the default any place in the Redux source that expects an action object.AnyAction
still 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-alpha
releases:createStore
deprecation tag portedisMinified
checkSet
Reducer
type accepts aPreloadedState
genericaction
andnext
are typed asunknown
action.type
field 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