redux-toolkit icon indicating copy to clipboard operation
redux-toolkit copied to clipboard

Errot in type StateFromReducersMapObject

Open AleksRap opened this issue 1 year ago • 2 comments

Hi everybody. I found an error inside the StateFromReducerMapObject type.

It plays back when I use async reducers.

For example

My state schema: interface SyncStateSchema { counter: CounterSchema; user: UserSchema; } export type AsyncStateSchema = { loginForm?: LoginSchema; profile?: ProfileSchema; }; export type StateSchema = SyncStateSchema & AsyncStateSchema;

where the loginForm and profile props are optional and are added to the global state (as well as cleared from there) when required

My type for reducers ReducersMapObject<StateSchema>

when I use the combineReducers function by passing my list of reducers to it, I get a function with the type: Reducer<{counter: CounterSchema, user: UserSchema, loginForm?: undefined, profile?: undefined}, UnknownAction, ...>

This is not exactly what I expected. I was waiting for the type: Reducer<{counter: CounterSchema, user: UserSchema, loginForm?: LoginSchema | undefined, profile?: ProfileSchema | undefined}, UnknownAction, ...>

this is true, because when the loginForm or profile state is connected, the reducer for it will exist, it will not always be undefined

AleksRap avatar Mar 01 '24 11:03 AleksRap