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
My form allows user to upload a file. At the initial state we have
typeMyTFormData={file?: File;// File can be undefined in the form};constform=useForm<MyTFormData>({defaultValues: {file: undefined,},onSubmit: async({ value })=>onFormCompleted(value),});
However I have a validator that ensures that file is set. The form is not submitted when file is undefined.
This is because the next steps of my app require a defined file.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
My form allows user to upload a file. At the initial state we have
However I have a validator that ensures that
file
is set. The form is not submitted whenfile
isundefined
.This is because the next steps of my app require a defined
file
.While my file field validator is indeed verifying that there is a defined
file
, the typing does not know it, andnaturally yields an error, because
MyTFormData
is not assignable toValidFormData
.Is there a way to make this guarantee carried across ? Maybe with typeguards in the validators?
Thanks
Beta Was this translation helpful? Give feedback.
All reactions