如何在使用Flow键入Redux操作创建程序时干掉类型定义?

时间:2018-02-21 17:37:09

标签: reactjs react-redux flowtype

我想知道如何干掉我的类型定义。让我们通过例子来解释:

actions.js

export type SearchProjectsAction = {
  type: 'SEARCH_PROJECTS',
  searchString: string
}

export type SetProjectSubNavigationAction = {
  type: 'SET_PROJECT_SUB_NAVIGATION',
  options: { id: number, offset: number }
}

export type Action =
  | SearchProjectsAction
  | SetProjectSubNavigationAction

export const searchProjects = (searchString: string): SearchProjectsAction => ({
  type: 'SEARCH_PROJECTS',
  searchString
})

export const setProjectSubNavigation = (options: { id: number, offset: number }): SetProjectSubNavigationAction => ({
  type: 'SET_PROJECT_SUB_NAVIGATION',
  options
})

component.js

type InputProps = {
  searchString: string
}

type Props = {
  hiddenCustomers: Array<number>,
  setProjectSubNavigation: ({ id: number, offset: number }) => void
} & InputProps

class Foo extends React.PureComponent<Props> {
  ...

  onScroll() {
    this.props.setProjectSubNavigation(null)
  }
}

const FooWithData = connect(
  state => ({
    hiddenCustomers: state.projects.hiddenCustomers
  }),
  {
    setProjectSubNavigation
  }
)(Foo)

const FooWithInputProps = (props: InputProps) => (
  <FooWithData { ...props } />
)

export default FooWithInputProps

因为我已经输入了setProjectSubNavigation方法,所以我不想在我的道具中输入调度函数时再次重复此操作(例如component.js中的第6行。

有什么方法可以说:

type Props = {
  hiddenCustomers: Array<number>,
  setProjectSubNavigation: some_type_thats_included_in_actions.js
} & InputProps

0 个答案:

没有答案