I’ve been facing a problem with @reduxjs/toolkit for several days. Despite adding node_modules to the exclude property and setting skipLibCheck=true in the tsconfig.json file, TypeScript still includes @reduxjs/toolkit in the type check.
I tried to update the @reduxjs/toolkit and TypeScript to the latest version, but the problem is still there. Can anyone help?
Below is the error
node_modules/@reduxjs/toolkit/src/query/react/ApiProvider.tsx:53:7 - error TS2322: Type '(gDM: GetDefaultMiddleware<any>) => Tuple<[ThunkMiddleware<any, UnknownAction>, Middleware<{}, RootState<{}, string, any>, ThunkDispatch<...>>]>' is not assignable to type '(getDefaultMiddleware: GetDefaultMiddleware<any>) => Tuple<Middlewares<any>>'.
Type 'Tuple<[ThunkMiddleware<any, UnknownAction>, Middleware<{}, RootState<{}, string, any>, ThunkDispatch<any, any, UnknownAction>>]>' is not assignable to type 'Tuple<Middlewares<any>>'.
Type '[ThunkMiddleware<any, UnknownAction>, Middleware<{}, RootState<{}, string, any>, ThunkDispatch<any, any, UnknownAction>>]' is not assignable
to type 'Middlewares<any>'.
Type 'ThunkMiddleware<any, UnknownAction> | Middleware<{}, RootState<{}, string, any>, ThunkDispatch<any, any, UnknownAction>>' is not assignable to type 'Middleware<{}, any, Dispatch<UnknownAction>>'.
Type 'ThunkMiddleware<any, UnknownAction>' is not assignable to type 'Middleware<{}, any, Dispatch<UnknownAction>>'.
Types of parameters 'next' and 'next' are incompatible.
Type 'unknown' is not assignable to type 'T'.
'T' could be instantiated with an arbitrary type which could be unrelated to 'unknown'.
53 middleware: (gDM) => gDM().concat(props.api.middleware),
~~~~~~~~~~
node_modules/@reduxjs/toolkit/dist/configureStore.d.ts:25:5
25 middleware?: (getDefaultMiddleware: GetDefaultMiddleware<S>) => M;
~~~~~~~~~~
The expected type comes from property 'middleware' which is declared here on type 'ConfigureStoreOptions<any, UnknownAction, Tuple<Middlewares<any>>, Tuple<[StoreEnhancer<{ dispatch: {}; }>, StoreEnhancer]>, any>'
this is my tsconfig file
{
"extends": "./tsconfig.json",
"compilerOptions": {
"target": "es6",
"module": "CommonJS",
"outDir": "../../dist/out-tsc",
"esModuleInterop": true,
"types": [
"node",
"@types/react-redux",
"@nx/react/typings/cssmodule.d.ts",
"@nx/react/typings/image.d.ts"
],
"skipLibCheck": true
},
"exclude": [
"../../node_modules/**/*.tsx",
"jest.config.ts",
"src/**/*.spec.ts",
"src/**/*.test.ts",
"src/**/*.spec.tsx",
"src/**/*.test.tsx",
"src/**/*.spec.js",
"src/**/*.test.js",
"src/**/*.spec.jsx",
"src/**/*.test.jsx"
],
"include": ["src/**/*"]
}
Typescript version is 5.3.2, reduxjs/toolkit version is 2.2.4
Nguyen Quang Phuc is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.