获取流错误:使用React-Redux连接器时“在对象文字中找不到属性”

时间:2017-05-31 19:56:30

标签: javascript reactjs redux react-redux flowtype

我查看了Redux流程示例并尝试在其后对此设置进行建模:https://github.com/reactjs/redux/blob/master/examples/todos-flow/src/containers/FilterLink.js

以下是代码:

// @flow

//imports...

type OwnProps = {
    dispatch: Dispatch,
    ownProp1: Object,
    ownProp2: string,
    ownProp3: string,
};

type Props = {
    action1: Function,
    action2: Function,
    action2: Function,
    reduxStateItem1: string,
    reduxStateItem2: Array<Object>,
} & OwnProps;

type AllProps = Props & OwnProps;

type State = {
    localStateItem1: boolean
};

class FullPanel extends Component {   //also tried <void, AllProps, State>
    props: AllProps;
    state: State;
    constructor(props) {
        super(props);

        this.state = {
            stateItem1: true,
        };
    }

...//other stuff

}

const mapStateToProps = (state: ReduxState) => {
    return {
        reduxStateItem1: state.reduxState1,
        reduxStateItem2: state.reduxState2,
    };
};

const mapDispatchToProps = (dispatch: Dispatch) => bindActionCreators({
    action1,
    action2,
    action3,
}, dispatch);

const connector: Connector<OwnProps, Props> = connect(
    mapStateToProps,
    mapDispatchToProps
);

export default connector(FullPanel);

问题是对于OwnProps,每个道具都抛出一个错误:“在对象文字中找不到属性”。我可以将它们标记为可选,然后它不会抛出错误,但它变得毫无意义(除了让人们知道道具应该是什么)。

此文件外部有一个功能组件,它渲染FullPanel并传入道具(OwnProps)。道具应该是从mapStateToProps和mapDispatchToProps注入的内容。

有一些方法可以让错误消失,但无论我把它作为类型放置(例如:将ownProp2更改为数字),流程总是会通过。

如果有人对这个特定问题有任何见解,或者如果有人能够解释为什么“在对象文字中找不到属性”被抛到这里,那真的很有帮助。谢谢。

编辑:https://github.com/reactjs/redux/issues/2207 - 这表明Props和OwnProps加入了。

0 个答案:

没有答案
相关问题