#Separation between internal and submitted types

5 messages · Page 1 of 1 (latest)

supple quartz
#

I think it would make sense for useForm({ defaultValue }) and field.handleChange to treat the value as Partial<> even if the field is required. That way defaultValue could specify only part of the type and handleChange could be called with undefined field.handleChange() to unset the field(e.g. for a file field)

silver pivot
chrome blade
#

If you want to use defaultValues as a partial, then type cast it 🙂

supple quartz
#

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.