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
foo
is undefined. What do I need to change here to make
a
a
optional so that it will not break if
bar
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