Zod schema
Unanswered
Prairie yellowjacket posted this in #help-forum
![Avatar](https://cdn.discordapp.com/embed/avatars/5.png)
Prairie yellowjacketOP
I have an array of objects in zod schema, I want to make service field required when type === "service" and I want to make richText field required when type === "richText", does anyone have an idea how to do that?
descriptions: z.array(
z
.object({
type: z.string(),
service: z.string(),
richText: z.string(),
})
),
2 Replies
![Avatar](https://cdn.discordapp.com/avatars/484037068239142956/f386ac21405ce3442e0f3598223e1cb3.webp?size=256)
joulev
something like this?
the ts type will be
z.array(
z.object({
type: z.literal("service"),
service: z.string().min(1),
}).or(z.object({
type: z.literal("richText"),
richText: z.string().min(1),
}))
)
the ts type will be
({ type: "service", service: string } | ( type: "richText", richText: string })[]
![Avatar](https://cdn.discordapp.com/embed/avatars/5.png)
Prairie yellowjacketOP
That looks good, I’ll try it, I managed to do it with refine but this seems so much simpler