首页 > 解决方案 > TypeScript 和 redux 工具包,createSlice:分配给函数参数“状态”的属性

问题描述

您好,我的 estlint 有问题:

分配给函数参数“状态”的属性。eslintno-param-重新分配

在这段代码上:

state.sideisOpen = action.payload;

interface SideBar {
  sideisOpen: boolean;
}

const INITIAL_STATE: SideBar = {
  sideisOpen: true,
};

const sideBar = createSlice({
  name: 'toggleSide',
  initialState: INITIAL_STATE,
  reducers: {
    toggleSide: (state, action: PayloadAction<boolean>) => {
      state.sideisOpen = action.payload;
    },
  },
});

export const { toggleSide } = sideBar.actions;
export { sideBar };

标签: typescriptredux

解决方案


请尝试编辑您的.eslintrc文件以使规则对您的情况不那么严格:

// .eslintrc
'no-param-reassign': ['error', {
      props: true,
      ignorePropertyModificationsFor: [
        'state',
      ]
    }],

推荐阅读