我正在学习 Angular11 中的状态管理。当我尝试制作减速器时出现错误。
类型参数 '(state: SharedState, action: { aspect_status: boolean; } & TypedAction<"[ side page ] side"> & { type: "[ side page ] aspect"; }) => { side: boolean; 微调器:布尔值;用户:用户;}' 不能分配给类型为 'OnReducer<SharedState, [ActionCreator<"[side page ] aspect", (props: { aspect_status: boolean; }) => { aspect_status: boolean; } & TypedAction<"[撇开页面]撇开">>]>'。
我试过这样
export interface SharedState {
spinner: boolean;
user: User;
aside: false;
}
export const Initial_State: SharedState = {
spinner: false,
user: <User>{},
aside: false,
};
export const loading = createAction(
Loading_Action,
props<{ spinner: boolean }>()
);
export const aside = createAction(
Aside_Action,
props<{ aside_status: boolean }>()
);
const _loading_reducer = createReducer(
Initial_State,
on(loading, (state, action) => {
return {
...state,
spinner: action.spinner,
};
}),
// getting error here
on(aside, (state, action) => {
console.log(action);
return {
...state,
aside: action.aside_status,
};
})
);
微调器一正常工作,但抛开错误。
但是当返回类型是任何错误时,不会。我想知道为什么会这样。