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
how to properly type the reducer #195
Comments
Couple things that might help:
|
I'm not sure if it's the best solution, but it seems like
|
Type 'Function' is not assignable to type 'Reducer<{}, AnyAction>' |
Please assist! UPD: ended up with temporary solution by adding:
|
The best way I ended up finding is to use the You can find an example here: https://github.com/Favna/ReactTSDemo/blob/master/src/store (note: also navigate to Edit: since the sample code above lacks connected-react-router use this as stand in for the import {
connectRouter, go, goBack, goForward,
push, replace, RouterState
} from 'connected-react-router';
// other imports
const routerActions = {
push: typeof push,
replace: typeof replace,
go: typeof go,
goBack: typeof goBack,
goForward: typeof goForward,
};
export type ApplicationState = Readonly<{
router: RouterState;
app: DemoState;
}>;
export function* rootSaga () {
yield all([fork(demoSaga)]);
}
export const rootActions = {
router: routerActions,
counter: counterActions,
};
export type RootAction = ActionType<typeof rootActions>;
export default (history: History) => combineReducers<ApplicationState>({
router: connectRouter(history),
app: DemoReducer,
}); |
Related to #173
versions:
I'm trying to declare my root state but I keep getting errors on History which I haven't been able to resolve after hours.
reducer.ts
type check
If I cannot solve this issue, I'll change
Reducer<RootState> → Reducer
andpersistReducer(…) → persistReducer(…) as any
, but this wouldn't be sane becore my exported RootState wouldn't guarantee that the expected state is correct.I understand that history is undefined at the beginning. Do you know of a way to say "that's ok" this way ?
The text was updated successfully, but these errors were encountered: