Type 'string[]' is not assignable to type 'string'.ts(2322) when trying to create a form using Prism

so I'm trying to create a submitForm using prisma, react-hook-form and zod and mysql as my database. But the problem I'm encountering right now is I get this error on form-submit.ts Type 'string[]' is not assignable to type 'string'.ts(2322) I know this comes from my schema.prisma, because upon reading the docs, on Scalar https://www.prisma.io/docs/orm/reference/prisma-schema-reference#-modifier
model AppoinmentSchedule {
id String @id @default(cuid())
doesHaveTCETAssitance String
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
model AppoinmentSchedule {
id String @id @default(cuid())
doesHaveTCETAssitance String
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
Since my zod accepts array.
export const formSchemaData = z.object({
doesHaveTCETAssitance: z.array(z.string()).refine((value) => value.some((item) => item), {
message: 'Please select at lease on the option'
}),

})
export const formSchemaData = z.object({
doesHaveTCETAssitance: z.array(z.string()).refine((value) => value.some((item) => item), {
message: 'Please select at lease on the option'
}),

})
form-submit.ts
export const submitForm = async (
values: z.infer<typeof formSchemaData>
) => {
const validatedFields = formSchemaData.safeParse(values)

if(!validatedFields.success){
return {error: "Form not submitted successfully!"}
}

const {
doesHaveTCETAssitance,
} = validatedFields.data

try {
await db.appoinmentSchedule.create({
data: {
doesHaveTCETAssitance,
}
})
} catch (error) {
return {error: "Something went wrong"}
}
}
export const submitForm = async (
values: z.infer<typeof formSchemaData>
) => {
const validatedFields = formSchemaData.safeParse(values)

if(!validatedFields.success){
return {error: "Form not submitted successfully!"}
}

const {
doesHaveTCETAssitance,
} = validatedFields.data

try {
await db.appoinmentSchedule.create({
data: {
doesHaveTCETAssitance,
}
})
} catch (error) {
return {error: "Something went wrong"}
}
}
Prisma Schema API | Prisma Documentation
API reference documentation for the Prisma Schema Language (PSL).
1 Reply
StoicWanderer
StoicWanderer8mo ago
Since MySQL doesn't support scalat lista natively, you could replace your schema with an enum if you definitely need to insert an array of strings into your databae with prisma.
Want results from more Discord servers?
Add your server