I have a configured project with React
, Redux
, Immutable.js
+ TypeScript
. During implementation I was trying to declare types as much as possible and found interesting issue. See code example below:
Short configuration of redux store
import { createStore } from 'redux';
import { combineReducers } from 'redux-immutable';
const rootReducer = combineReducers({...});
const store = createStore(rootReducer);
Somewhere inside component
// ...
const mapStateToProps = (state: ReturnType<typeof rootReducer>) => {
// state is plain object :(
};
On state hover in VS Code, tooltip shows that state is a plain object, however it is not. It should be a custom collection from Immutable.js
How can I get a correct type of rootReducer
? Or what I am doing wrong?
Screenshots:
P.S. StateType
and ReturnType
do the same stuff
This works (no need for Immutable.js):
export type RootState = ReturnType<typeof rootReducer>;
If for some reason it does not works, this one should work:
export type RootState = ReturnType<typeof store.getState>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With