I’m setting up an app with React-Redux and configured the store, similar to the guide shown here
Here is my code:
import { applyMiddleware, compose, createStore } from 'redux';
import thunkMiddleware from 'redux-thunk';
import rootReducer from '../reducers/reducers'
export default function configureStore() {
const middlewares = [thunkMiddleware];
const middlewareEnhancer = applyMiddleware(...middlewares);
const enhancers = [middlewareEnhancer];
const composedEnhancers = compose(...enhancers);
const preloadedState = (<any>window).__PRELOADED_STATE__;
delete (<any>window).__PRELOADED_STATE__;
const store = createStore(rootReducer, preloadedState, composedEnhancers);
return store;
}
However, I keep receiving the following Typescript error when I run build
TS2345: Argument of type '(...args: any[]) => {}' is not assignable to parameter of type 'StoreEnhancer<{}, {}>'.
I’m confused. Doesn’t Redux’s declaration file state (shown below) that the StoreEnhancer simply receives the Store and State extensions as empty plain objects?
export type StoreEnhancer<Ext = {}, StateExt = {}> = (next: StoreEnhancerStoreCreator) => StoreEnhancerStoreCreator<Ext, StateExt>
If so, why wouldn’t it accept 'Any' type from the rest parameters, even though I set “noImplicitAny” property to "true" in the config file, as shown below?
(To the best of my knowledge, rest parameters can’t receive a declared type anyway.)
What am I missing?
Also, I’m using the following package versions:
"react": "^16.4.2",
"redux": "^4.0.0",
"redux-thunk": "^2.3.0",
"webpack": "^4.16.5",
"awesome-typescript-loader": "^5.2.0",
"typescript": "^3.0.3"
"@types/react": "^16.4.12",
"@types/redux": "^3.6.0",
"@types/redux-thunk": "^2.1.0"
with the following TS config settings:
"compilerOptions": {
* "outDir": "./dist/",
* "sourceMap": true,
* "noImplicitAny": true,
* "module": "esnext",
* "target": "esnext",
* "jsx": "react",
* "moduleResolution": "node",
* "noUnusedLocals": true,
* "noUnusedParameters": true,
* "strict": true,
* "esModuleInterop": false,
* "noFallthroughCasesInSwitch": true,
* "allowSyntheticDefaultImports": true
}