TS2339: Property does not exist in type 'IntrinsicAttributes & IntrinsicClassAttributes <FormInstance <{}, Partial <ConfigProps <{}, {} >>>> & ...'
I am new to typescript and redux, and I'm trying to work with the SimpleForm example from redux-form.
I have the following form component
import * as React from 'react';
import {Field, reduxForm} from 'redux-form';
class SimpleForm extends React.Component<any, any> {
public render() {
const { handleSubmit, doCancel } = this.props;
return (
<div>
<h1>Simple Form</h1>
<form onSubmit={handleSubmit}>
<div>
<label htmlFor="firstName">First Name</label>
<Field name="firstName" component="input" type="text" />
<label htmlFor="lastName">Last Name</label>
<Field name="lastName" component="input" type="text" />
</div>
<div>
<button type="button" onClick={doCancel}>Cancel</button>
<button type="submit">Submit</button>
</div>
</form>
</div>
)};
}
export default reduxForm({ form: "simpleForm" })(SimpleForm);
And I use the component with
return (
<div>
<SimpleForm onSubmit={this.handleSubmit} doCancel={this.doCancel} />
</div>
);`
This gives me the following error:
TS2339: Property 'doCancel' does not exist on type 'IntrinsicAttributes & IntrinsicClassAttributes<FormInstance<{}, Partial<ConfigProps<{}, {}>>>> & ...'.
if I remove doCancel prop so that the form displays normally, but obviously the cancel button does not work.
What am I doing wrong here?
+4
1 answer
You need to add some characters to your form.
import { reduxForm, InjectedFormProps } from 'redux-form';
interface Props {
doCancel():
}
class SimpleForm extends React.Component<InjectedFormProps<any, Props> & Props> {
....
}
export default reduxForm<any, Props>({ form: "simpleForm" })(SimpleForm);
. , .
0