Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

issue: useForm array defaultValue type-mismatch with useFieldArray actions #8781

Closed
1 task done
charkour opened this issue Aug 2, 2022 · 4 comments
Closed
1 task done
Labels
question Further information is requested TS Typescript related issues

Comments

@charkour
Copy link

charkour commented Aug 2, 2022

Version Number

7.34.0

Codesandbox/Expo snack

https://codesandbox.io/s/nice-night-mqqcgz?file=/src/App.tsx

Steps to reproduce

Longtime users, first time making an issue.

With the recent type changes in #8660 to the useFieldArray action types, there is now a type error when field values are omitted in append, but there is no type error when omitting values in the useForm default values.

To repro:

  1. Open sandbox link
  2. Notice the field values on line 8 are not optional
  3. Notice on line 20 that the default value is omitting a required value
  4. Notice on line 56 that there is a correct type error which was fixed in fix field array type incorrectness #8660 (released in v7.34.0)

Expected behaviour

Prior to v7.34.0, line 56 would not error which I agree is a bug. However, should line 20 also give the same type of error? Looking at the documentation, it says "It is encouraged that you set defaultValues for all inputs to non-undefined values such as the empty string or null." This seems to say that the current behavior of allowing the omission of required fields in defaultValues is expected.

In my opinion, the type behavior useForm({ defaultValues }) should match the updates to append. What do you think?

My initial idea is to update the type definition of DefaultValues in form.ts to be type DefaultValues<TFieldValues> = TFieldValues but I'm not sure if that is the best solution. What do you think?

Thanks for your time!

What browsers are you seeing the problem on?

No response

Relevant log output

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct
@charkour charkour changed the title issue: useForm array defaultValue type-mismatch with useFieldArray issue: useForm array defaultValue type-mismatch with useFieldArray actions Aug 2, 2022
@bluebill1049
Copy link
Member

Screen Shot 2022-08-03 at 8 39 03 am

thanks for the issue report, if you refer to the doc all payloads for each action are not optional. This is very important as this is create many issues in which users are supplied with partial data which leads to stale input value after action. This type of update fixes that and prevent more issues occurred at the user end. In fact, in the next major update, defaultValues will remove deep partial as well.

@bluebill1049 bluebill1049 added question Further information is requested TS Typescript related issues labels Aug 2, 2022
@charkour
Copy link
Author

charkour commented Aug 3, 2022

Great, I'm happy to hear that in a future version the defaultValues type will have deep partial removed which will then match the payloads for the actions.

If you don't plan on making that type change until v8, then we can close this issue. Thanks for the quick response and for the work you do!

@Moshyfawn Moshyfawn closed this as not planned Won't fix, can't repro, duplicate, stale Aug 3, 2022
@bluebill1049
Copy link
Member

Thanks for understanding @charkour if we can provide a valid bug/issue for useForm without deepPartial, we can certainly discuss and potentially make the change to fix those problems. useFieldArray is definitely a type bug and lead to unexpected behaviors which reported several bugs which coming to the root cause of missing defaultValue due to optional type. Let us know.

@charkour
Copy link
Author

charkour commented Aug 3, 2022

Great, sounds good. I'm fine with the current solution. Thank you!

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 9, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
question Further information is requested TS Typescript related issues
Projects
None yet
Development

No branches or pull requests

3 participants