From bf9193e7bc6b4023b139c7c28b0b9964fc7a0381 Mon Sep 17 00:00:00 2001 From: Renaud Chaput Date: Fri, 29 Mar 2024 22:27:56 +0100 Subject: [PATCH] Add a note to ignore `@typescript-eslint/ban-types` rule when typing middlewares See the discussion here: https://github.com/reduxjs/redux-toolkit/discussions/4312#discussioncomment-8955685 --- docs/usage/UsageWithTypescript.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/docs/usage/UsageWithTypescript.md b/docs/usage/UsageWithTypescript.md index 5de3adaecb..087bf0cc41 100644 --- a/docs/usage/UsageWithTypescript.md +++ b/docs/usage/UsageWithTypescript.md @@ -280,6 +280,12 @@ export const exampleMiddleware: Middleware< } ``` +:::caution + +If you are using `typescript-eslint`, the `@typescript-eslint/ban-types` rule might report an error if you use `{}` for the dispatch value. The recommended changes it makes are incorrect and will break your Redux store types, you should disable the rule for this line and keep using `{}`. + +::: + The dispatch generic should likely only be needed if you are dispatching additional thunks within the middleware. In cases where `type RootState = ReturnType` is used, a [circular type reference between the middleware and store definitions](https://github.com/reduxjs/redux/issues/4267) can be avoided by switching the type definition of `RootState` to: