为对象方法添加自定义流类型

时间:2019-01-24 16:45:48

标签: javascript flowtype

我想通过添加flow type重新引用我的方法。我的实际代码:

const apiActions = {
  registerThroughApi: async (
    state: Object,
    action: Function,
    formData: Object
  ): Object => {
    return state;
  }
};

是否可以添加flow type

type Form = {
  state: Object,
  action: Function,
  formData: Object
}

const apiActions = {
  registerThroughApi: async (state, action, formData)<Form>: Object => {
    return state;
  }
};

但是此代码不起作用:D

有人知道这是否可能吗?

谢谢社区!

1 个答案:

答案 0 :(得分:0)

不确定我是否完全理解,但是这样的事情

// @flow

const apiActions = {
  registerThroughApi: async (state: Object, action: Function, formData: Object): Object => {
    return state;
  }
};