Good day.
I need help with the following issue. A while back we updated our project to use Angular 12 and I have been trying to update @ngrx/store from v10 to v11 (or v12). I did try this update when we were still using Angular 11 as well, but I keep getting this error:
Argument of type 'ReducerTypes<unknown, [ActionCreator<"EnableForm", () => TypedAction<"EnableForm">>]>' is not assignable to parameter of type 'ReducerTypes<AppState, ActionCreator<string, Creator<any[], object>>[]>'.
Types of property 'reducer' are incompatible.
Type 'OnReducer<unknown, [ActionCreator<"EnableForm", () => TypedAction<"EnableForm">>]>' is not assignable to type 'OnReducer<AppState, ActionCreator<string, Creator<any[], object>>[]>'.
Type 'unknown' is not assignable to type 'AppState'.
My reducer looks something like this:
import { Action, createReducer, on } from '@ngrx/store';
import * as MyAction from '../actions';
import { AppState } from '../state';
import { onEnableForm, onDisableForm } from './form.reducer';
const initialState: AppState = {
form: {
disabled: false,
...
},
...
};
export function storeReducer(state: AppState = initialState, action: Action): AppState {
return createReducer<AppState>(
state,
on(MyAction.InitializeState, MyAction.ResetState, () => initialState),
on(MyAction.DestroyState, () => undefined),
onEnableForm,
onDisableForm
)(state, action);
}
actions.ts looks like this:
import { createAction } from '@ngrx/store';
export const InitializeState = createAction('[MyFeatureStore] InitializeState');
export const ResetState = createAction('[MyFeatureStore] ResetState');
export const DestroyState = createAction('[MyFeatureStore] DestroyState');
export const EnableForm = createAction('[MyFeatureStore] EnableForm');
export const DisableForm = createAction('[MyFeatureStore] DisableForm');
And form.reducer.ts looks like this:
import { on } from '@ngrx/store';
import * as MyAction from '../actions';
import { AppState } from '../state';
export const onEnableForm = on(MyAction.EnableForm, (state: AppState) => {
return {
...state,
form: {
...state.form,
disabled: false
}
};
});
export const onDisableForm = on(MyAction.DisableForm, (state: AppState) => {
return {
...state,
form: {
...state.form,
disabled: true
}
};
});
This works okay in v10, but I can't figure out why it's not working in v11.