supasate / connected-react-router

A Redux binding for React Router v4
MIT License
4.73k stars 593 forks source link

Strongly typed combine reducers #214

Open neuralsea opened 5 years ago

neuralsea commented 5 years ago

I am new to react / redux and would appreciate the guidance of a more expert hand in helping me understand and resolve the issue below: (the general approach, how to fix and an understanding of why it has happened)

index.ts

// example requires export default (history) => combineReducers({ router: connectRouter(history), layout: layoutReducer })

export interface ApplicationState { router: RouterState, layout: LayoutState }

export default (history) => combineReducers({ router: connectRouter(history), layout: layoutReducer })

configureStore.js

... import createRootReducer from 'connected-react-router/lib/reducer';

export default function configureStore(history: History, initialState: ApplicationState) : Store { const composeEnhancers = composeWithDevTools({}); const sagaMiddleware = createSagaMiddleware();

const store = createStore( createRootReducer(history), initialState, composeEnhancers(applyMiddleware(routerMiddleware(history), sagaMiddleware)) )

sagaMiddleware.run(rootSaga);

return store;

store faults with the error tree below: X is not assignable to type 'Store<ApplicationState, AnyAction>'.

Types of property 'getState' are incompatible. Y' is not assignable to type '() => ApplicationState'.

Types of property 'router' are incompatible. Y'' is not assignable to type 'RouterState'.

Types of property 'location' are incompatible. Y''' is not assignable to type 'Location'. Types of property 'pathname' are incompatible. Y'''' is not assignable to type 'string'.

How do I resolve these errors (on reducers etc...?)

neuralsea commented 5 years ago

export default function configureStore(history: History, initialState: ApplicationState) : Store<ApplicationState> {