如何将模型分配给模型数组?

时间:2019-06-14 06:12:15

标签: angular angular7 typescript-typings

我正在尝试将模型分配给模型数组。但出现错误。该如何解决?

这是我的代码:

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;
    }
}
来自打字稿编译器的

出现以下错误。附加的屏幕截图:

error as screenshot

1 个答案:

答案 0 :(得分:0)

我用数组括号更新了状态,现在可以正常工作了。这是更新的代码:

export function reducerSubSystem(state = initialState, action: ssAction.subSystemTypes): ModelSubSystem[] {
    switch (action.type) {

        case ssAction.LoadSubSystemSuccess.TYPE:
            return {
                ...state,

            };

        default:
            return state;
    }
}