Reactjs 有未使用的';合并DPROPS&x27;参数在';连接';组件渲染时引发错误
我正在为我当前的Typescript React项目使用Redux,但要进入其中有点困难。不过,到目前为止,连接组件对我来说还不错Reactjs 有未使用的';合并DPROPS&x27;参数在';连接';组件渲染时引发错误,reactjs,typescript,redux,react-redux,Reactjs,Typescript,Redux,React Redux,我正在为我当前的Typescript React项目使用Redux,但要进入其中有点困难。不过,到目前为止,连接组件对我来说还不错 interface OwnProps { ownProp?: boolean; } interface PropsFromState { stateProp: any; } interface PropsFromDispatch { dispatchProp: (...) => void; } type MyComponentPr
interface OwnProps {
ownProp?: boolean;
}
interface PropsFromState {
stateProp: any;
}
interface PropsFromDispatch {
dispatchProp: (...) => void;
}
type MyComponentProps = OwnProps & PropsFromState & PropsFromDispatch;
class MyComponent extends React.Component<MyComponentProps> {...}
const mapStateToProps = ({ componentState }: IAppState, ownProps: OwnProps): PropsFromState => {
return {
stateProp: componentState.stateProp,
ownProp: ownProps.ownProp,
};
};
const mapDispatchToProps = (dispatch: any): PropsFromDispatch => {
return {
dispatchProp: (...) => dispatch(dispatchProp(...))
};
};
export default connect<PropsFromState, PropsFromDispatch, OwnProps>(
mapStateToProps,
mapDispatchToProps
)(MyComponent);
但是因为我必须将mergedProps
的第三个参数放在两者之间(我认为可以默认为null
,没有任何问题),tslint
现在在我尝试渲染组件时为我抛出一个错误,比如
<MyComponent ownProp ref={ref => this.comp = ref}/>
Type '{ ownProp: true; ref: (ref: Component<Pick<MyComponent, "ownProp" | "stateProp" | "dispatchProp"> & OwnProps, any, any>) => Component<...>; }' is missing the following properties from type 'Readonly<Pick<MyComponentProps, "ownProp" | "stateProp" | "dispatchProp"> & OwnProps>': stateProp, dispatchProp - ts(2739)
this.comp=ref}/>
类型“{ownProp:true;ref:(ref:Component)=>Component;}”缺少类型“Readonly”中的以下属性:stateProp,dispatchProp-ts(2739)
似乎组件现在需要其他不需要的道具。知道如何处理这个问题吗?在谷歌搜索了很多次之后,我最终导出了连接和未连接的组件,连接用于redux,未连接用于使用ref。这对我来说是可行的,但仍然在寻找一些真正的答案。
<MyComponent ownProp ref={ref => this.comp = ref}/>
Type '{ ownProp: true; ref: (ref: Component<Pick<MyComponent, "ownProp" | "stateProp" | "dispatchProp"> & OwnProps, any, any>) => Component<...>; }' is missing the following properties from type 'Readonly<Pick<MyComponentProps, "ownProp" | "stateProp" | "dispatchProp"> & OwnProps>': stateProp, dispatchProp - ts(2739)