#Separation between internal and submitted types
5 messages · Page 1 of 1 (latest)
totally agree. i have a form where i want a select field to be undefined by default, but the type makes it a required field of a union. I dont have to set the single select to one of the req. values since i want to force a user to select it and validate it
so im not sure how to
- use defaultValues as partial
- validate the form as a stricter type of the data, including any required fields
Doing so would fundamentally break the way our type inferencing works and cause an awful lot of headaches with most users:
https://github.com/TanStack/form/issues/705#issuecomment-2135943113
Describe the bug I'm wondering if this was a design decision (I've seen it in RHF), but I feel like it is still incorrectly typed somewhere. A Field's field.state.value will have whatev...
If you want to use defaultValues as a partial, then type cast it 🙂
Hmm. Seems incorrect. If there is no defaultValue provided then the type of state.value is not the same as useForm<X> (i.e. X). It can't be. Without defaultValue the correct typing of state.value is Partial<X>.
I wonder if a better solution would be to hold onto two types in the Form type useForm<X, InternalX>. Then something like zod could take InternalX and transform it into X. Partial isn't actually good enough because you don't want to have to deal with the case where prop x is X | undefined when you actually did provide a default value.