Skip to content

Commit 4afef4a

Browse files
authored
Merge pull request #3968 from reduxjs/override-dep-section
2 parents 167ba5d + 04df604 commit 4afef4a

File tree

1 file changed

+51
-1
lines changed

1 file changed

+51
-1
lines changed

docs/usage/migrating-rtk-2.md

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ We've changed `next` to be `(action: unknown) => unknown` (which is accurate, we
134134

135135
In order to safely interact with values or access fields inside of the `action` argument, you must first do a type guard check to narrow the type, such as `isAction(action)` or `someActionCreator.match(action)`.
136136

137-
This new type is incompatible with the v4 `Middleware` type, so if a package's middleware is saying it's incompatible, check which version of Redux it's getting its types from!
137+
This new type is incompatible with the v4 `Middleware` type, so if a package's middleware is saying it's incompatible, check which version of Redux it's getting its types from! (See [overriding dependencies](#overriding-dependencies) later in this page.)
138138

139139
#### `PreloadedState` type removed in favour of `Reducer` generic
140140

@@ -723,6 +723,56 @@ We now have a docs page that covers [how to set up Redux properly with Next.js](
723723

724724
(At this time, the Next.js `with-redux` example is still showing outdated patterns - we're going to file a PR shortly to update that to match our docs guide.)
725725

726+
## Overriding dependencies
727+
728+
It will take a while for packages to update their peer dependencies to allow for Redux core 5.0, and in the meantime changes like the [Middleware type](#middleware-type-changed---middleware-action-and-next-are-typed-as-unknown) will result in perceived incompatibilities.
729+
730+
It's likely that most libraries will not actually have any practices that are incompatible with 5.0, but due to the peer dependency on 4.0 they end up pulling in old type declarations.
731+
732+
This can be solved by manually overriding the dependency resolution, which is supported by both `npm` and `yarn`.
733+
734+
### `npm` - `overrides`
735+
736+
NPM supports this through an [`overrides`](https://docs.npmjs.com/cli/v9/configuring-npm/package-json#overrides) field in your `package.json`. You can override the dependency for a specific package, or make sure that every package that pulls in Redux receives the same version.
737+
738+
```json title="Individual override - redux-persist"
739+
{
740+
"overrides": {
741+
"redux-persist": {
742+
"redux": "^5.0.0"
743+
}
744+
}
745+
}
746+
```
747+
748+
```json title="Blanket override"
749+
{
750+
"overrides": {
751+
"redux": "^5.0.0"
752+
}
753+
}
754+
```
755+
756+
### `yarn` - `resolutions`
757+
758+
Yarn supports this through a [`resolutions`](https://classic.yarnpkg.com/lang/en/docs/selective-version-resolutions/) field in your `package.json`. Just like with NPM, you can override the dependency for a specific package, or make sure that every package that pulls in Redux receives the same version.
759+
760+
```json title="Individual override - redux-persist"
761+
{
762+
"resolutions": {
763+
"redux-persist/redux": "^5.0.0"
764+
}
765+
}
766+
```
767+
768+
```json title="Blanket override"
769+
{
770+
"resolutions": {
771+
"redux": "^5.0.0"
772+
}
773+
}
774+
```
775+
726776
## Recommendations
727777

728778
Based on changes in 2.0 and previous versions, there have been some shifts in thinking that are good to know about, if non-essential.

0 commit comments

Comments
 (0)