Javascript 更新数组对象内的值

Javascript 更新数组对象内的值,javascript,arrays,reactjs,typescript,react-redux,Javascript,Arrays,Reactjs,Typescript,React Redux,我只想用用户输入的新名称替换名称。我正在使用react-redux类型脚本,事实证明这相当困难。所有传入的参数都有效,newName和index,我只需要更新数组对象,然后返回它,只更改索引对象中的名称 我的代码: 行动: export const updateName = (newName: string, index: number) => ( dispatch: (arg0: { type?: string; newName: string; index: number }) =

我只想用用户输入的新名称替换
名称
。我正在使用react-redux类型脚本,事实证明这相当困难。所有传入的参数都有效,
newName
index
,我只需要更新数组对象,然后返回它,只更改索引对象中的名称

我的代码:

行动:

export const updateName = (newName: string, index: number) => (
  dispatch: (arg0: { type?: string; newName: string; index: number }) => any
) => {
  dispatch({
    type: UPDATE_NAME,
    newName,
    index
  });
};
减速器:

case UPDATE_NAME:
      return {
        ...state
        items[action.index].name: action.newName,

      };
国家看起来是这样的:

items: Array(50)
0: {id: "1d0b1095-f0b4-4881-8d5e-74c86d5beee2", name: "A Ipsum Debitis", participants: {…},
1: {id: "7384a574-1592-484e-9404-e876bf45410c", name: "Distinctio Blanditiis Voluptatibus Ut", participants: {…},

除了浅层复制state对象外,还需要浅层复制正在更新的任何嵌套状态,即
state.items
和正在更新的特定数组元素

case UPDATE_NAME:
  return {
    ...state,
    items: state.items.map((el, i) => i === action.index ? {
      ...el,
      name: action.newName,
    } : el),
  };

我得到这个消息“(参数)el:never-Spread类型只能从对象类型创建。ts(2698)“…(el为{}),似乎是这样工作的far@artworkjpm没错,你需要输入map回调函数。似乎
el
的类型类似于
{id:string,name:string,participants:any}