I am currently utilizing the useFormik
hook to handle my form. The userId
field is a select
, so by default its value is set to null
. However, my validationSchema
requires this field to be populated before submission.
const formik = useFormik<ApiCreditDebitCreateInput>({
initialValues: {
userId: null, // TypeScript warning: Type 'null' is not assignable to type 'string'.ts
},
validationSchema: schema,
onSubmit,
});
Despite this, I am encountering a Typescript warning regarding the assignment of null
to userId
:
Type 'null' is not assignable to type 'string'.ts(2322)
I am unsure how to address this issue as null
is a valid initial value for userId
, but it will not pass validation based on my schema.
Maintaining this schema simplifies my onSubmit
logic as I can avoid checking for null values there.
Thank you!