我使用nrgx /存储和下面的示例应用程序,我使用类强类型我的动作像打字稿 - 指定类型的多种类型
export const ActionTypes ={
SET_ACTIVE_USER: type('[UserState] Set Active User'),
SET_USERLIST: type('[UserState] Set Userlist')
};
export class SetActiveUserAction implements Action {
type = ActionTypes.SET_ACTIVE_USER;
constructor(public payload:User){}
}
export class SetUserlistAction implements Action {
type = ActionTypes.SET_USERLIST;
constructor(public payload:User[]){}
}
export type Actions
= SetActiveUserAction
| SetUserlistAction
我现在正在为一个导出变量在我的减速机中输入问题。由于导出操作的类型可以是用户或用户的[],它不会让我分配用户列表:用户[]它(我想使用数组方法,如的forEach)来处理这个
export function reducer(state = INITIAL_STATE, action: userAction.Actions): State {
switch (action.type) {
case userAction.ActionTypes.SET_USERLIST: {
let userlist:User[] = action.payload <-------Type Issue
return tassign(state, { userlist: action.payload })
}
default: {
return state
}
}
}
https://github.com/ngrx/example-app/issues/127 – cartant