You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
Open sandbox link
Notice the field values on line 8 are not optional
Notice on line 20 that the default value is omitting a required value
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
The text was updated successfully, but these errors were encountered:
charkour
changed the title
issue: useForm array defaultValue type-mismatch with useFieldArray
issue: useForm array defaultValue type-mismatch with useFieldArray actions
Aug 2, 2022
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.
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!
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.
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 theuseForm
default values.To repro:
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 indefaultValues
is expected.In my opinion, the type behavior
useForm({ defaultValues })
should match the updates toappend
. What do you think?My initial idea is to update the type definition of
DefaultValues
in form.ts to betype 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
The text was updated successfully, but these errors were encountered: