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

typescript: unclear how to appease compose's typings when using redux dev tools #1937

Closed
tamird opened this issue Sep 7, 2016 · 4 comments
Closed

Comments

@tamird
Copy link

tamird commented Sep 7, 2016

Prior to #1868 it was possible to use https://github.com/zalmoxisus/redux-devtools-extension as we do in CRDB: https://github.com/cockroachdb/cockroach/blob/develop/ui/app/redux/state.ts#L27:L51

After #1868, this produces the following error:

TypeScript [Error] file:///Users/tamird/src/go/src/github.com/cockroachdb/cockroach/ui/app/redux/state.ts:36:3
TypeScript [Error] Type 'Func0<{}, StoreEnhancerStoreCreator<{}>>' cannot be converted to type 'StoreEnhancer<AdminUIState>'.
  Type 'StoreEnhancerStoreCreator<{}>' is not comparable to type 'StoreEnhancerStoreCreator<AdminUIState>'.
    Type 'Store<{}>' is not comparable to type 'Store<AdminUIState>'.
      Type '{}' is not comparable to type 'AdminUIState'.
        Property 'routing' is missing in type '{}'. (TS2352)

I'm not really sure if this is a bug in the typings or if we're doing something wrong in our code, but any help would surely be appreciated.

/cc @aikoven

@aikoven
Copy link
Collaborator

aikoven commented Sep 8, 2016

Here's how I do it:

import {createStore, applyMiddleware, compose, GenericStoreEnhancer} from 'redux';

const devToolsExtension: GenericStoreEnhancer = window['devToolsExtension'] ?
  window['devToolsExtension']() : f => f;

const store = createStore(rootReducer,
  compose(
    applyMiddleware(sagaMiddleware),
    devToolsExtension
  ) as GenericStoreEnhancer
);

Assuming that rootReducer is typed as Reducer<MyState>, store gets type Store<MyState>.

@tamird
Copy link
Author

tamird commented Sep 8, 2016

Yep, replacing StoreEnhancer<AdminUIState> with GenericStoreEnhancer did it. Thanks!

@franleplant
Copy link

For future reference, this made the trick for me reduxjs/redux-thunk#51 (comment)

TLDR:

Do not use compose and use only applyMiddleware, it does the trick in newer versions of Redux

@sjdweb
Copy link

sjdweb commented Oct 10, 2017

Hi - struggled with this for a while... Found the easiest way for me was to install redux-devtools-extension (which has built-in typings) and use it like so:

import { composeWithDevTools } from 'redux-devtools-extension';

const store = createStore(reducer, composeWithDevTools(
  applyMiddleware(...middleware),
  // other store enhancers if any
));

This replaced my use of compose().

This was taken from redux devtools docs.

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

4 participants