我有一个在打字稿中定义如下的工作区对象:
export interface OneWorkspace {
id: number;
name: string;
roles: WorkspaceRole[]
users: WorkspaceUser[]
logs: WorkspaceLog[]
channels?: OneWorkspaceChannels
}
在channels
对象中有2个对象:groups
和channels
export interface OneWorkspaceChannels {
channels: OneWorkspaceChannel[]
groups: OneWorkspaceGroup[]
}
export interface OneWorkspaceChannel {
id: number;
name: string;
}
export interface OneWorkspaceGroup {
id: number;
name: string;
channel: OneWorkspaceChannel[]
}
当用户创建一个新通道或组时,我想将新通道/组添加到我现有的工作空间对象中,并添加到channel对象中的相应对象。 在我的reducer中,对于新的频道或新的组,我得到以下值:
newChannels: OneWorkspaceChannel[] | undefined,
newGroups: OneWorkspaceGroup[] | undefined
我尝试在我的减速器中执行以下操作,但这不起作用:
case getType(actions.CreateChannelGroup.success):
return {
...state,
createChannelGroupStatus: action.payload.CreateChannelGroupStatus,
createChannelMessage: action.payload.createChannelMessage,
workspace: {
...state.workspace,
channels: {
...state.workspace!.channels!,
channels: [...state.workspace!.channels!.channels!, action.payload.newChannels! ]
}
}
}
如何正确地向工作空间对象添加新频道或组?