Why "createReducer" return type isn't a deox/dist/types/Reducer?
See original GitHub issueFor those who received a incomplete issue in email, I am sorry, I have hit enter accidentally before finishing.
Now, to the issue:
I am trying to pass a Reducer as a parameter to a method, but I get a compile error about the types.
Please let me know if I am using the library wrong:
Error:(61, 27) TS2345: Argument of type ‘(state: DeepImmutableArray<Param> | undefined, action: { type: string; payload: Param; } | { type: string; payload: { index: number; param: Param; }; } | { type: string; payload: { fromIndex: number; toIndex: number; }; }) => Param[] | DeepImmutableArray<…>’ is not assignable to parameter of type ‘Reducer<DeepImmutableArray<Param>, { type: string; payload: Param; } | { type: string; payload: { index: number; param: Param; }; } | { type: string; payload: { fromIndex: number; toIndex: number; }; }>’. Types of parameters ‘state’ and ‘prevState’ are incompatible. Property ‘[Symbol.iterator]’ is missing in type ‘DeepImmutableObject<DeepImmutableArray<Param>>’ but required in type ‘DeepImmutableArray<Param>’.
export function createParamTableReducer(
actions: ParamTableActionCreators
): Reducer<Param[]> {
const deoxReducer = createReducer([] as Param[], (handle) => [
handle(actions.addParam, (state, { payload }) =>
produce(state, (draft: Draft<Param[]>) => {
draft.push(payload);
})
),
handle(actions.removeParam, (state, { payload }) =>
produce(state, (draft: Draft<Param[]>) => {
draft.splice(payload.index, 1);
})
),
handle(actions.updateParam, (state, { payload }) =>
produce(state, (draft: Draft<Param[]>) => {
draft[payload.index] = payload.param;
})
),
handle(actions.reorderParams, (state, { payload }) =>
produce(state, (draft: Draft<Param[]>) => {
draft.splice(payload.fromIndex, 1);
draft.splice(payload.toIndex, 0, state[payload.fromIndex]);
})
),
]);
return normalizeReducer(deoxReducer);
}
import { Reducer } from "deox/dist/types";
import { Action, Reducer as ReduxReducer } from "redux";
export function normalizeReducer<T, A extends Action>(
deoxReducer: Reducer<T, A>
): ReduxReducer<T, A>
Why doesn’t “createReducer” uses the existing Reducer type as a returnType?
Issue Analytics
- State:
- Created 4 years ago
- Comments:19 (19 by maintainers)

Top Related StackOverflow Question
That is exactly what I was looking for. I am not a “typescript expert” so I have not yet understood the
inferkeyword completely.Your example made it clear in my mind, Thank you very much
It should be declared like how Action type was declared. By inferring the return type of
HandlerMap(s).I hope I understood your question correctly. If not, excuse me for my bad English and please ask your question with more details.