我正在尝试将Redux添加到React应用程序中。我快到了,但是我似乎无意中暴露了状态组件,并且在父组件中遇到了错误。这是我的组件:
interface StateProps {
myValue: number;
}
interface OwnProps { }
interface DispatchProps { }
type Props = OwnProps & StateProps & DispatchProps;
interface State {
value1: boolean,
value2: boolean
}
export class MyComponent extends Component<Props, State> {
...
}
function mapStateToProps(state: AppStore) {
return {
myValue: state.myValue
};
}
export default connect<StateProps, DispatchProps, OwnProps, AppStore>(mapStateToProps)(MyComponent);
我的问题是Typescript无法编译。父组件:
render () {
return (
<div>
<MyComponent/>
</div>
);
}
给出以下错误:
类型“ {}”中缺少属性“ myValue”,但类型为“ Readonly”时必需。ts(2741)
Clearly I've misunderstood something about how Own
and State
props work - I thought that only the contents of OwnProps
should be exposed, although, I'll admit, I'm unclear how Typescript would determine which is which.