我正在尝试将模型分配给模型数组。但出现错误。该如何解决?
这是我的代码:
export interface ModelSubSystem {
Id: number;
Name: string;
CreatedBy: string;
CreatedDate: Date;
UpdatedBy: string;
UpdatedDate: Date;
}
const initialState: Array<ModelSubSystem> {
subsystems: []
};
export function reducerSubSystem(state = initialState, action: ssAction.subSystemTypes): ModelSubSystem {
switch (action.type) {
case ssAction.LoadSubSystemSuccess.TYPE:
return {
...state,
};
default:
return state;
}
}
来自打字稿编译器的出现以下错误。附加的屏幕截图:
答案 0 :(得分:0)
我用数组括号更新了状态,现在可以正常工作了。这是更新的代码:
export function reducerSubSystem(state = initialState, action: ssAction.subSystemTypes): ModelSubSystem[] {
switch (action.type) {
case ssAction.LoadSubSystemSuccess.TYPE:
return {
...state,
};
default:
return state;
}
}