Error with Redux DevTools Extension using TS: “Property '__REDUX_DEVTOOLS_EXTENSION_COMPOSE__' does not exist on type 'Window'.”?

前端 未结 7 1811
一个人的身影
一个人的身影 2021-02-01 12:43

I\'m getting this error on my index.tsx.

Property \'REDUX_DEVTOOLS_EXTENSION_COMPOSE\' does not exist on type \'Window\'.

Here is my index.tsx

7条回答
  •  暖寄归人
    2021-02-01 13:26

    if any one still stuck into this issue I fixed it and this is my final store.js file with following packages 1- Redux Thunk 2- Connected React Router 3- History

    import { createStore, applyMiddleware, compose } from 'redux';
    import { routerMiddleware } from 'connected-react-router';
    import thunk from 'redux-thunk';
    import {createBrowserHistory} from 'history';
    import rootReducer from '../redux/reducers';
    export const history = createBrowserHistory();
    const initialState = {}
    const enhancers = []
    const middleware = [
        thunk,
        routerMiddleware(history)
    ]
    
    if (process.env.NODE_ENV === 'development') {
        const devToolsExtension = (window as any).__REDUX_DEVTOOLS_EXTENSION__ && (window as any).__REDUX_DEVTOOLS_EXTENSION__() || compose;
        if (typeof devToolsExtension === 'function') {
            enhancers.push(devToolsExtension)
        }
    }
    
    const composedEnhancers = compose(
        applyMiddleware(...middleware),
        ...enhancers
    );
    
    export default createStore(
        rootReducer,
        initialState,
        composedEnhancers
    );
    

提交回复
热议问题