Revisolution / typed-redux-kit

Scaffoldings for Redux with Typescript
19 stars 5 forks source link

[Typings] batchEnhancer doesn't work well with compose #4

Closed Rokt33r closed 7 years ago

Rokt33r commented 7 years ago

You probably can fix it by ordering and providing a proper generic. I'm going to add more test for this to fix.

  const store = createStore<RootState>(reducer, compose(
    batchEnhancer<RootState>(sagaMiddleware), // should come first with generic
    applyMiddleware(...middlewares),
  ));

Also this requires redux-saga@^0.15.6.

This is a typing issue. It won't bother you if you are not using typescript.

Rokt33r commented 7 years ago

From 0.4.2, we can do this by 2 ways.

  1. Provide state generic to each enhancer.
const sagaMiddleware = createSagaMiddleware<State>()
const middlewareEnhancer: Redux.StoreEnhancer<State> = applyMiddleware(sampleMiddleware)
const enhancer = compose(
  middlewareEnhancer,
  batchEnhancer(sagaMiddleware),
)
  1. Provide state generic to compose method
const sagaMiddleware = createSagaMiddleware()
const middlewareEnhancer = applyMiddleware(sampleMiddleware)
const enhancer = compose<Redux.StoreEnhancerStoreCreator<State>>(
  middlewareEnhancer,
  batchEnhancer(sagaMiddleware),
)