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
ReducerNameStateDatatype (the raw, JSON-serializable state)
export type MyReducerStateData = {
currentUser: string;
data: {
loaded: boolean;
};
};- Define
ReducerNameStatetype, which extendsImmutable.Mapand 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
ReducerNameStatein the actual reducer function andcreateStore()call