Skip to content

Commit

Permalink
Merge pull request #3968 from reduxjs/override-dep-section
Browse files Browse the repository at this point in the history
  • Loading branch information
markerikson committed Dec 9, 2023
2 parents 167ba5d + 04df604 commit 4afef4a
Showing 1 changed file with 51 additions and 1 deletion.
52 changes: 51 additions & 1 deletion docs/usage/migrating-rtk-2.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ We've changed `next` to be `(action: unknown) => unknown` (which is accurate, we

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)`.

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!
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.)

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

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

(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.)

## Overriding dependencies

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.

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.

This can be solved by manually overriding the dependency resolution, which is supported by both `npm` and `yarn`.

### `npm` - `overrides`

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.

```json title="Individual override - redux-persist"
{
"overrides": {
"redux-persist": {
"redux": "^5.0.0"
}
}
}
```

```json title="Blanket override"
{
"overrides": {
"redux": "^5.0.0"
}
}
```

### `yarn` - `resolutions`

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.

```json title="Individual override - redux-persist"
{
"resolutions": {
"redux-persist/redux": "^5.0.0"
}
}
```

```json title="Blanket override"
{
"resolutions": {
"redux": "^5.0.0"
}
}
```

## Recommendations

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.
Expand Down

0 comments on commit 4afef4a

Please sign in to comment.