I'm currently working on adding optional support for cover images for my site. However, I only want to require a field coverAlt if the cover field is set. I've tried using a refine function in my config.ts (basically coverAlt: z.string().refine((schema) => schema.cover !== undefined)) but I've been unable to get that to work. Is there a way I can have it be required if the cover field is set?
#Requiring one field based on another in content collections?
1 messages · Page 1 of 1 (latest)
Still waiting for an answer?
It looks like no-one has responded to your question yet. People might not be available right now or don’t know how to answer your question. Want an answer while you wait? Try asking our experimental bot in #1095492539085230272.
You can use discriminated unions
https://zod.dev/?id=discriminated-unions
Example: TS Playground