如何将keyMirror与flow一起使用?

时间:2016-12-20 08:27:39

标签: javascript reactjs-flux flowtype

在我的flux / react设置中,我将ActionTypes定义为keyMirror。

export const ActionType = keyMirror({
  START_TIMER: null,
  STOP_TIMER: null,
  PERFORM_STARTUP_CHECKS: null,
  SELECT_TASK_SERVICE:null,
  ADD_TASK: null,
  CLEAR_ALL_TASKS: null,
  COMPLETE_TASK: null,
  UNDO_COMPLETE_TASK: null,
  EDIT_TASK_TEXT: null,
});

然后我按如下方式定义不同类型的Action:

export type TaskAction = {
 type: ActionType.ADD_TASK,
 text: string
} | {
 type: ActionType.COMPLETE_TASK,
 taskId: string 
}

export type TimerAction = {
  type: ActionType.START_TIMER
} | {
  type: ActionType.STOP_TIMER
}

这些不同类型的动作对应于不同的商店。例如。

In TasksStore
.
.
  reduce(state: TasksList, action: TaskAction) 

In TimerStore 
.
.
reduce(state: State, action: TimerAction) 

但是,当我运行流程时,无法识别该操作。

 56:         indexOfTask = state.findIndex(function(task){ return task.get('_id') === action.taskId});
                                                                                             ^^^^^^ property `taskId`. Property not found in
 56:         indexOfTask = state.findIndex(function(task){ return task.get('_id') === action.taskId});
                                                                                      ^^^^^^ object type

0 个答案:

没有答案