我使用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