-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
defaultValues Partial / DeepPartial causes unsafe typings #8510
Comments
Additionally, in a stricter mode, |
100% buy-in on this, we are moving away |
If it's slated for V8, then that's perfect for me! Great to know. I'll leave a note there now. |
yes, we are definitely going ahead of that, especially since the lazy field path may have to be reverted due to the ts 4.7 change. |
Is your feature request related to a problem? Please describe.
Consider the following:
The type inference for
useForm
is very good, but forcing a partial opens it up to unnecessary runtime errors.In situations where your form may not have values present, it should instead be typed appropriately:
Describe the solution you'd like
A few approaches come to mind:
DeepPartial
. This would be a breaking change and possibly upset developers that do not want strict typing.useFormStrict
with a strict type definition. It would use the same runtime code asuseForm
useForm
to beuseForm<TFieldValues, TContext = any, TStrictValues = false>(...)
. The types could leverageTStrictValues
to conditionally useDeepPartial
.Describe alternatives you've considered
The current workaround is to strictly define your default values upfront:
This has the "pit of failure" downside--if developers forget to do this, they may encounter runtime errors later.
Additional context
Happy to contribute changes here if we want to make an adjustment for current or future version.
The text was updated successfully, but these errors were encountered: