Z
Zod•7d ago
hinogi

hinogi - tsconst a = z.object({ foo: z.strin...

const a = z.object({
foo: z.string()
})

const b = z.object({
bar: z.lazy(() => a().nullish)
})

b.parse({bar: {}})
const a = z.object({
foo: z.string()
})

const b = z.object({
bar: z.lazy(() => a().nullish)
})

b.parse({bar: {}})
this will error because foo is undefined. What do I need to change here to make a optional so that it will not break if bar is just empty since foo should be optional?
Solution:
ok so foo has to be foo: null | undefined and {} is not a valid solutions. also, if null, the key will persist, if undefined the key is gone 😄 thanks playground
Jump to solution
6 Replies
hinogi
hinogiOP•7d ago
bit additional background, such a thing is generated by graphql codegen schema validation, I try to figure out how to fix this for optional input types depending on non nullable input properties
Unknown User
Unknown User•7d ago
Message Not Public
Sign In & Join Server To View
hinogi
hinogiOP•7d ago
sure but I am not sure if it needs to be
const b = z.object({
bar: z.lazy(()=> a.nullish()).nullish()
})
const b = z.object({
bar: z.lazy(()=> a.nullish()).nullish()
})
or something
Solution
hinogi
hinogi•6d ago
ok so foo has to be foo: null | undefined and {} is not a valid solutions. also, if null, the key will persist, if undefined the key is gone 😄 thanks playground
hinogi
hinogiOP•6d ago
No description

Did you find this page helpful?