我注意到几件事:
1)据我在示例中看到的以及
props在Typescript中使用时,您对的调用
React.Component需要
Props像这样指定类型参数:
export default class TestPage extends React.Component<Test.Props, Test.State>{ constructor(props: Test.Props) { super(props); }}您可以指定您的组件不接受
props或
state通过传递空接口,即:
export default class TestPage extends React.Component<{}, {}>{ // constructor becomes 'useless' at this point and is not needed constructor() { super(); }}我认为这可以解释您的呼叫签名不匹配的原因,以及为什么看不见任何属性
this.props-TS看到一个接口,
ReadOnly{}因为它没有传入类型参数。2)您的
mapStateToProps功能看起来不太正确。
mapStateToProps接受两个参数
state((引用您的Redux
store)和
ownProps作为可选的第二个参数,该参数引用
props从父级传递过来的参数)。因此
mapStateToProps应如下所示:
function mapStateToProps(state: any, ownProps: { label: string }) { return { label: ownProps.label };}这是我为什么
connect会引发错误的猜测-
在这里,您只是断言Redux应该如何处理
props来自
store和
props来自父代的合并。让我知道是否可行。



