1

I'm converting my project to Typescript.

This has always worked for me in JS.

/* ##################### */
/* #### REDUX STORE #### */
/* ##################### */

const store = createStore(rootReducer, {
  // INITIAL STATE GOES HERE
},window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__());

But in Typescript I'm getting these errors:

enter image description here

enter image description here

enter image description here

How can I fix this?

2 Answers 2

3

The error is getting throw from the TS compiler because it doesn't know about REDUX_DEVTOOLS_EXTENSION property on the Window object. You can extend the Window interface and add that which will make the TS compiler happy. Or you can do this:

createStore(rootReducer,{//INITIAL STATE GOES HERE},composeWithDevTools());

cite: https://redux.js.org/recipes/configuring-your-store#integrating-the-devtools-extension

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks! Can I leave this on for production? Or should I bother removing it?
That probably depends on if you have a consumer-facing app or not, if you're storing secrets in state, etc? I don't personally think it's a big deal but YMMV. Here's what I found just from a quick google search: medium.com/@zalmoxis/… and here's how to exclude them if you want - github.com/reduxjs/redux-devtools/blob/master/docs/…
Even better, you should use our official Redux Toolkit package, which has a configureStore function that automatically enables the Redux DevTools Extension for you.
2

the easiest solution i found is to explicitly add __REDUX_DEVTOOLS_EXTENSION_COMPOSE__ to the window object

declare global {
  interface Window {
  __REDUX_DEVTOOLS_EXTENSION_COMPOSE__?: typeof compose;
  }
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.