redux-devtools
redux-devtools copied to clipboard
TS2344: Type 'unknown' does not satisfy the constraint '{}'
Using:
"redux": "^5.0.1",
"@redux-devtools/extension": "^3.3.0",
I get:
node_modules/@redux-devtools/extension/lib/types/index.d.ts:227:70 - error TS2344: Type 'unknown' does not satisfy the constraint '{}'.
227 (config: Config): <StoreEnhancers extends readonly StoreEnhancer<unknown>[]>(...funcs: StoreEnhancers) => StoreEnhancer<InferComposedStoreExt<StoreEnhancers>>;
~~~~~~~
node_modules/@redux-devtools/extension/lib/types/index.d.ts:227:125 - error TS2344: Type 'InferComposedStoreExt<StoreEnhancers>' does not satisfy the constraint '{}'.
Type 'unknown' is not assignable to type '{}'.
Type 'unknown' is not assignable to type '{}'.
227 (config: Config): <StoreEnhancers extends readonly StoreEnhancer<unknown>[]>(...funcs: StoreEnhancers) => StoreEnhancer<InferComposedStoreExt<StoreEnhancers>>;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Maybe this was broken by https://github.com/reduxjs/redux/commit/5a084a62fda9ebf39ffa969458d9950b4f051688:
- export type StoreEnhancer<Ext = {}, StateExt = never>
+ export type StoreEnhancer<Ext extends {} = {}, StateExt extends {} = {}>
I've updated the bug to reflect the error that this (new) extension gives me.
Workaround (or solution?):
After installing the library, in node_modules/@redux-devtools/extension/lib/types/index.d.ts and node_modules/@redux-devtools/extension/lib/types/logOnly.d.ts, change all occurrences of StoreEnhancer<...> to StoreEnhancer<... & {}>.
Note that you shouldn't be using either the core redux package or @redux-devtools/extension directly in your own code today. Instead, use Redux Toolkit's configureStore, which sets that up for you automatically:
- https://redux.js.org/usage/migrating-to-modern-redux#store-setup-with-configurestore
Right. Still.
I think this TypeScript error happens irrespective of what APIs I call, and just because of the mere existence of node_modules/@redux-devtools/extension/lib/types/index.d.ts in my TypeScript inputs -- and that wouldn't go away with the Toolkit.
(I'm lazy about such a migration... Despite the claim "This is a one-time step, and all of the existing reducers and middleware will continue to work as-is." I ran into TypeScript errors last time and decided to postpone this.)
@Philipp91 fwiw, that should go away with RTK and configureStore, because RTK does not depend on @redux-devtools/extension itself - it inlines some of the types. So yeah, migrating the store setup to RTK would be one way to fix this.
I'd also recommend checking to see if you somehow have multiple copies of redux in your node_modules.
Okay thanks, I've managed to migrate with reasonable effort and I can confirm that the issue doesn't show up there. As you suspected, it doesn't install the redux-devtools module at all then.
(No multiple copies. I believe the error comes from a misalignment of redux-devtools code with the updated redux code I linked in the opening post.)