v5.0.0-beta.0
Pre-releaseThis 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
npm i redux@next
yarn add redux@next
Changelog
New UnknownAction
Type
The Redux TS types have always exported an AnyAction
type, which is defined to have {type: string}
and treat any other field as any
. This makes it easy to write uses like console.log(action.whatever)
, but unfortunately does not provide any meaningful type safety.
We now export an UnknownAction
type, which treats all fields other than action.type
as unknown
. 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:
if (todoAdded.match(someUnknownAction)) {
// action is now typed as a PayloadAction<Todo>
}
Earlier Alpha Changes
Summarizing changes from the earlier 5.0-alpha
releases:
- Source code converted to TS
createStore
deprecation tag ported- Removed
isMinified
check - Packaging converted to have full ESM/CJS compatibility
- Dropped UMD build artifacts
- JS build output is now "modern" and not transpiled for IE11 compatibility
- Listener subscriptions are now a
Set
- Store enhancer types improved
Reducer
type accepts aPreloadedState
generic- Middleware
action
andnext
are typed asunknown
action.type
field must be a string
What's Changed
- Prefer use of Action or UnknownAction instead of AnyAction by @EskiMojo14 in #4520
Full Changelog: v5.0.0-alpha.6...v5.0.0-beta.0