Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TS2344: Type 'unknown' does not satisfy the constraint '{}' #1596

Open
Philipp91 opened this issue Jan 6, 2024 · 6 comments
Open

TS2344: Type 'unknown' does not satisfy the constraint '{}' #1596

Philipp91 opened this issue Jan 6, 2024 · 6 comments

Comments

@Philipp91
Copy link

Philipp91 commented Jan 6, 2024

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 reduxjs/redux@5a084a6:

- export type StoreEnhancer<Ext = {}, StateExt = never>
+ export type StoreEnhancer<Ext extends {} = {}, StateExt extends {} = {}>
@Philipp91 Philipp91 changed the title TS2344: Type  StoreExt  does not satisfy the constraint  {} TS2344: Type 'unknown' does not satisfy the constraint '{}' Jan 6, 2024
@Philipp91
Copy link
Author

I've updated the bug to reflect the error that this (new) extension gives me.

@Philipp91 Philipp91 reopened this Jan 6, 2024
@Philipp91
Copy link
Author

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<... & {}>.

@markerikson
Copy link

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:

@Philipp91
Copy link
Author

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

@markerikson
Copy link

markerikson commented Jan 7, 2024

@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.

@Philipp91
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants