yarn @reduxjs/toolkit 1.2.0
v1.2.0

latest releases: 2.2.3, 2.2.2, 2.2.1...
4 years ago

This release rewrites the createAction and createSlice types to enable better user readability and reusability, and fixes an issue with the bundling and publishing of the immutable state invariant middleware.

(Note: this release was broken due to a missing TS type definition file. Please use v1.2.1 instead.)

Changes

Type Inference Readability Improvements

The type definitions for createAction and createSlice were primarily written using the TS type keyword. The TS compiler and inference engine tries to "unwrap" those types, which meant that the inferred type for a variable like const test = createAction<number, 'test'>('test') would be shown in an IDE tooltip like this:

WithTypeProperty<WithMatch<(<PT extends number>(payload: PT) => WithPayload<PT, Action<"test">>), "test", number, never, never>, "test">

That unwrapped type declaration is hard to read, and not very informative for app developers.

We've rewritten most of our types to use the interface keyword instead. Now, that same variable's inferred type would be displayed as:

ActionCreatorWithPayload<number, "test">

This is more informative and easier to read.

Type Export Improvements

Several users had noted that the complexity of the type definitions for createSlice made it impossible to write a higher-order or wrapper function in TypeScript that called createSlice internally ( #276, #286). As part of the typings update, we've refactored the type declarations to expose some public types that can be used to correctly define the arguments that will be passed to createSlice, and documented how to wrap createSlice in the "Usage with TypeScript" docs page. We've also documented all of the types in the codebase.

Thanks to @phryneas for all the hard work on these type improvements!

Module Bundling Fixes

The build tooling setup for RTK tries to deal with several different use cases (dev vs prod, CJS vs ESM vs UMD modules, etc). There were problems with the build config that resulted in a require() statement being included in the ESM build, and the UMD dev build was actually missing the immutable invariant middleware. The build tooling has been updated to fix those issues.

Changelog

v1.1.0...v1.2.0

Don't miss a new toolkit release

NewReleases is sending notifications on new releases.