フロータイプのレポからのreact-reduxタイピングを使用して、reduxプロジェクトでフロータイプ(0.43.0)をテストするという混乱した動作を経験しました。フロータイプはインポートされたレキシコンテナの小道具をチェックしていません
// @flow
import React from 'react'
import {connect} from 'react-redux'
class ChildComponent extends React.Component {
props: {
value: string,
otherValue: string
}
render() {
return <span>{ this.props.value && this.props.otherValue }</span>
}
}
function mapStateToProps(state) {
return {otherValue: "test"}
}
const ConnectedChildComponent = connect(mapStateToProps)(ChildComponent)
class ParentComponent extends React.Component {
render() {
return <ConnectedChildComponent/>
}
}
上記のコードは、期待どおりに型推論を実行し、「値」プロパが設定されるべきであることを示す、親での使用にエラーを報告します。
私は別のファイルにコンテナの子コードを移動するときしかし、私は、です。TypeCheckは(暗黙の「は任意の」インポートするには可能性が高い)
// flowTestPatent.js
// @flow
import React from 'react'
import {connect} from 'react-redux'
import ConnectedChildComponent from './flowTestChild'
class ParentComponent extends React.Component {
render() {
return <ConnectedChildComponent/>
}
}
//flowTestChild.js
// @flow
import React from 'react'
import {connect} from 'react-redux'
export class ChildComponent extends React.Component {
props: {
value: string,
otherValue: string
}
render() {
return <span>{ this.props.value && this.props.otherValue }</span>
}
}
function mapStateToProps(state) {
return {otherValue: "test"}
}
export default connect(mapStateToProps)(ChildComponent)
上記のコードレポートエラーなし起こらないことが判明それは最初の例と同等でなければならないようです。私は何とか間違ってインポートを実行していると仮定しますが、接続されていないコンポーネントをインポートすると、typecheckingは期待通りに行われます。誰でもここで何が起こっているのかを説明できますか?ありがとう!
を取得します。同じファイルであっても、接続されたコンポーネントの使用状況をタイプチェックする必要はありません。私は "react-redux"から 'import type {Connector} 'として" Connector "タイプをインポートしており、フローはコードを正しいものとして報告しています。 – SJH
すべてのコードを含むように更新されました。つまり、フローエラーが発生します。 ConnectedChildComponentに値propを追加すると、エラーが解決されます。 – TLadd