5

First of all, I'm very new to TS, React & Redux, so sorry if this is an obvious question.

I'm trying to modify this example to get a form to load some information. It's using redux-form.

I'm trying to figure out how to call connect and redux-form at the same time in the export of the component. Right now it's looking like this:

class UserForm extends React.Component<IUserProps, void> { .. }

export default ReduxForm.reduxForm({
  form: 'user',
  fields: [
    'userName',
    'password',
    'firstName',
    'lastName',
    'email'
  ],
  validate: UserForm.validate,
})(UserForm);

The examples I've seen without TS look like this:

class MyForm extends Component {}
MyForm = reduxForm(config)(MyForm)
MyForm = connect(mapStateToProps, mapDispatchToProps)(MyForm)
export default MyForm

But if I try to do the same in TS I get the TS2300 error: duplicate identifier.

I've also tried to use the @connect decorator, but I couldn't make it work (or find any working example online).

Leo Lozes
  • 1,358
  • 1
  • 15
  • 33

2 Answers2

5

Can you just chain them?

class UserForm extends React.Component<IUserProps, void> { .. }

export default connect(mapStateToProps,mapDispatchToProps) 
    (ReduxForm.reduxForm({
  form: 'user',
  fields: [
    'userName',
    'password',
    'firstName',
    'lastName',
    'email'
  ],
  validate: UserForm.validate,
})(UserForm));
Alejandro C.
  • 3,771
  • 15
  • 18
2

not a fix, but issue can be silenced by casting to any

connect(mapStateToProps, mapDispatchToProps)(MyForm as any)

zowers
  • 587
  • 6
  • 13