Z
Zod12mo ago
janglad

janglad - Am I missing something or is it not p...

Am I missing something or is it not possible to make a primitive required? I have a use case where this would make sense
import z from "zod"

const schema1 = z.object({
value: z.string().optional()
})

const schema2 = z.object({
value: schema1.shape.value.required()
})
import z from "zod"

const schema1 = z.object({
value: z.string().optional()
})

const schema2 = z.object({
value: schema1.shape.value.required()
})
Solution:
This is a bit iffy to do, but I think schema.shape.value.unwrap().required() should work.
Jump to solution
2 Replies
Solution
Sikari
Sikari12mo ago
This is a bit iffy to do, but I think schema.shape.value.unwrap().required() should work.
janglad
jangladOP12mo ago
yes indeed just .unwrap() seems to be doing the trick thank you!
Want results from more Discord servers?
Add your server