react-final-form
react-final-form copied to clipboard
Breaking TypeScript changes in v7.0.0 (and final-form v5.0.0)
Hi @erikras,
First, thank you for maintaining this library and for the Flow → TypeScript migration! 🙏
The release notes for v7.0.0 state "There should be NO BREAKING CHANGES", but we encountered several TypeScript breaking changes during our migration from v6.5.7 to v7.0.0.
Here's a comprehensive list:
react-final-form v7.0.0
| Change | Impact | Fix |
|---|---|---|
| FormState.values can now be undefined | All usages of values.property fail | Use values?.property or values ?? {} |
| FormState.dirty, pristine, valid, etc. can be undefined | Boolean checks fail (e.g., dirty && ...) | Use dirty ?? false |
| FieldMetaState type is no longer exported | Import fails | Use FieldRenderProps<T>['meta'] instead |
| AnyObject type is no longer exported | Import fails | Define locally: type AnyObject = Record<string, any> |
| UseFieldConfig is no longer generic | UseFieldConfig<T> fails |
Use UseFieldConfig (no generic) |
| FormProps no longer accepts arbitrary props like style | <Form style={...}> fails | Wrap with a <div style={...}> |
final-form v5.0.0
| Change | Impact | Fix |
|---|---|---|
| InternalFormState now requires asyncErrors property | Test mocks fail | Add asyncErrors: {} to mock objects |
| Mutator type signature changed | Jest mocks incompatible | Cast with as unknown as Mutator |
Migration effort
For our medium-sized codebase, we had to modify 170+ files. The changes are straightforward but numerous.
Suggestion
It would be helpful to either:
- Document these TypeScript changes in the release notes
- Or add a migration guide for TypeScript users
Environment:
- react-final-form: 6.5.7 → 7.0.0
- final-form: 4.20.4 → 5.0.0
- TypeScript: 5.5.4