Defines the app's Redux store using TypeScript to add type safety and improve developer documentation.
The general strategy to get TypeScript to work nicely with ImmutableJS is to:
- Define
ReducerNameStateData
type (the raw, JSON-serializable state)
export type MyReducerStateData = {
currentUser: string;
data: {
loaded: boolean;
};
};
- Define
ReducerNameState
type, which extendsImmutable.Map
and overrides some methods
export interface MyReducerState extends ImmutableMap<string, any> {
toJS(): MyReducerStateData;
get<K extends keyof MyReducerStateData>(key: K, notSetValue?: MyReducerStateData[K]): MyReducerStateData[K];
set<K extends keyof MyReducerStateData>(key: K, val: MyReducerStateData[K]): MyReducerStateData;
}
- Use the
ReducerNameState
in the actual reducer function andcreateStore()
call