Differentiate the type of the field state value and the validation result?
Lets take this example:
I would like a field to be initially
null
and respect this type also during rendering, but after successful validation it's required an therefor the type should omit the null
. So basically:
- field.state.value
should have the type null | { street: string }
- value
in onSubmit
should have the type { address: { street: string } }
(omitting the null
for address
)
What's the recommended solution? My usecase is a MUI Autocomplete which is initially empty and omitting the null
completely doesn't feel right to me.0 Replies