使用Flowtype覆盖React-Redux Connect()

问题描述 投票:1回答:2

我有以下代码:

const mapStateToFilterProps = (state:DataExplorerState, props) => ({ loading: state.loading, filters: state.filters });

const actionCreators: ActionCreators<string, Action> = { updateLoadState, updateFilters, updateChartData};

const mapDispatchToProps = (dispatch: Dispatch<Action>) => bindActionCreators(actionCreators, dispatch)

// TODO: Fix typing issue
export const FilterBoxConnect = connect(
    mapStateToFilterProps, 
    mapDispatchToProps
)(FilterBox)

“TODO”下面的代码表示它已被发现。我该怎么说呢?

reactjs redux react-redux flowtype static-analysis
2个回答
1
投票

我认为它被发现是因为connect不需要在0.85之前明确注释。在0.85之后,Flow将ask for required annotations。基本上,如果我们在导出时没有显式注释连接的组件,Flow将报告“隐式实例化”错误:

Missing type annotation for OP. OP is a type parameter declared in function type [1] and was implicitly
instantiated at call of connect [2].

此外,我们现在能够通过提供类型参数显式地注释connect

import * as React from 'react'

type OwnProps = {|
  passthrough: string,
  forMapStateToProps: string
|}

type Props = {|
  ...OwnProps,
  fromMapStateToProps: string,
  dispatch1: () => void
|}

const MyComponent = (props: Props) => (
  <div onClick={props.dispatch1}>
    {props.passthrough}
    {props.fromMapStateToProps}
  </div>
)

export default connect<Props, OwnProps, _, _, _, _>(
  mapStateToProps,
  mapDispatchToProps
)(MyComponent)

我有一个更详细的指南here


0
投票

问题可能已得到解决。我不知道,我没有测试它,但维护者声称情况就是这样:Exhibit AExhibit B

© www.soinside.com 2019 - 2024. All rights reserved.