I am trying to pass custom props to my component which is decorated with reduxForm. Also I am very new in Typescript.
The first problem is that I can't wrap the decorated component with connect:
export default
connect(mapStateToProps)(
reduxForm({
form: 'myform'
})(MyComponent)
)
The error:
Error:(89, 5) TS2345:Argument of type 'DecoratedComponentClass<any, Partial<ConfigProps<any, {}>>>' is not assignable to parameter of type 'ComponentType<{ addressValue: any; isDeliveryAddress: any; customerTypeValue: any; } & DispatchPr...'.
Type 'DecoratedComponentClass<any, Partial<ConfigProps<any, {}>>>' is not assignable to type 'StatelessComponent<{ addressValue: any; isDeliveryAddress: any; customerTypeValue: any; } & Dispa...'.
Type 'DecoratedComponentClass<any, Partial<ConfigProps<any, {}>>>' provides no match for the signature '(props: { addressValue: any; isDeliveryAddress: any; customerTypeValue: any; } & DispatchProp<any> & { children?: ReactNode; }, context?: any): ReactElement<any> | null'.
It's obviously caused by wrong types but as I said I am new in Typescript and I am not sure how to deal with these long errors. At this moment I don't need to pass any props to the validate form function but it will be very helpful for future tasks.
The main problem is that I can't pass custom props to the decorated component:
export default reduxForm({
form: 'myform'
})(
connect(mapStateToProps)(MyComponent)
);
the form props:
interface Props extends InjectedFormProps {
onSubmit: () => void;
// some values from the state
loading: boolean; // the custom prop
}
and when I try this:
<MyForm loading onSubmit={this.handleSubmit} />
it throws another error:
Error:(134, 25) TS2339:Property 'loading' does not exist on type 'IntrinsicAttributes & IntrinsicClassAttributes<FormInstance<any, Partial<ConfigProps<any, {}>>>> ...'.
The strange part is that I am able to pass props that are declared in the InjectedFormProps interface but I can't pass any custom props. Actually, I am able to pass any props from the mapStateToProps function. Maybe I just can't pass any custom props to the decorated component with reduxForm.