import * as vi from "vitest"
import { zx } from "@traversable/zod"
// Using `zx.deepPartial.writeable` here to make it easier to visualize `zx.deepPartial`'s behavior:
vi.expect.soft(zx.deepPartial.writeable(
z.object({
a: z.number(),
b: z.string(),
c: z.object({
d: z.array(z.object({
e: z.number().max(1),
f: z.boolean()
})).length(10)
})
})
)).toMatchInlineSnapshot
(`
"z.object({
a: z.number().optional(),
b: z.string().optional(),
c: z.object({
d: z.array(z.object({
e: z.number().max(1).optional(),
f: z.boolean().optional()
})).length(10).optional()
}).optional()
})"
`)
zx.deepPartialConverts an arbitrary zod schema into its "deeply-partial" form.
That just means that the schema will be traversed, and wrap all z.object z.object
properties with z.optional z.optional.
zx.deepPartial's behavior is configurable at the typelevel via
the defaults.typelevel options.typelevel property:
defaults.typelevel "semantic" (default): leave the schema untouched, but wrap it
in a no-op interface (zx.deepPartial.Semantic) to make things explicit
defaults.typelevel "applyToTypesOnly": apply the transformation to the schema's
output type and wrap it in z.ZodType z.ZodType
defaults.typelevel "preserveSchemaType": zx.deepPartial will
return what it got, type untouched
Note:
Make sure you understand the semantics of deepPartial
before you use this in production. There's a reason it was removed from zod proper.
This library trusts users to do their due diligence to make sure they understand
the tradeoffs.
import * as vi from "vitest"
import { zx } from "@traversable/zod"
// Using `zx.deepPartial.writeable` here to make it easier to visualize `zx.deepPartial`'s behavior:
vi.expect.soft(zx.deepPartial.writeable(
z.object({
a: z.number(),
b: z.string(),
c: z.object({
d: z.array(z.object({
e: z.number().max(1),
f: z.boolean()
})).length(10)
})
})
)).toMatchInlineSnapshot
(`
"z.object({
a: z.number().optional(),
b: z.string().optional(),
c: z.object({
d: z.array(z.object({
e: z.number().max(1).optional(),
f: z.boolean().optional()
})).length(10).optional()
}).optional()
})"
`)
zx.deepPartialConverts an arbitrary zod schema into its "deeply-partial" form.
That just means that the schema will be traversed, and wrap all z.object z.object
properties with z.optional z.optional.
zx.deepPartial's behavior is configurable at the typelevel via
the defaults.typelevel options.typelevel property:
defaults.typelevel "semantic" (default): leave the schema untouched, but wrap it
in a no-op interface (zx.deepPartial.Semantic) to make things explicit
defaults.typelevel "applyToTypesOnly": apply the transformation to the schema's
output type and wrap it in z.ZodType z.ZodType
defaults.typelevel "preserveSchemaType": zx.deepPartial will
return what it got, type untouched
Note:
Make sure you understand the semantics of deepPartial
before you use this in production. There's a reason it was removed from zod proper.
This library trusts users to do their due diligence to make sure they understand
the tradeoffs.
import * as vi from "vitest"
import { zx } from "@traversable/zod"
// Using `zx.deepPartial.writeable` here to make it easier to visualize `zx.deepPartial`'s behavior:
vi.expect.soft(zx.deepPartial.writeable(
z.object({
a: z.number(),
b: z.string(),
c: z.object({
d: z.array(z.object({
e: z.number().max(1),
f: z.boolean()
})).length(10)
})
})
)).toMatchInlineSnapshot
(`
"z.object({
a: z.number().optional(),
b: z.string().optional(),
c: z.object({
d: z.array(z.object({
e: z.number().max(1).optional(),
f: z.boolean().optional()
})).length(10).optional()
}).optional()
})"
`)
zx.deepPartialConverts an arbitrary zod schema into its "deeply-partial" form.
That just means that the schema will be traversed, and wrap all z.object z.object
properties with z.optional z.optional.
zx.deepPartial's behavior is configurable at the typelevel via
the defaults.typelevel options.typelevel property:
defaults.typelevel "semantic" (default): leave the schema untouched, but wrap it
in a no-op interface (zx.deepPartial.Semantic) to make things explicit
defaults.typelevel "applyToTypesOnly": apply the transformation to the schema's
output type and wrap it in z.ZodType z.ZodType
defaults.typelevel "preserveSchemaType": zx.deepPartial will
return what it got, type untouched
Note:
Make sure you understand the semantics of deepPartial
before you use this in production. There's a reason it was removed from zod proper.
This library trusts users to do their due diligence to make sure they understand
the tradeoffs.
import * as vi from "vitest"
import { zx } from "@traversable/zod"
// Using `zx.deepPartial.writeable` here to make it easier to visualize `zx.deepPartial`'s behavior:
vi.expect.soft(zx.deepPartial.writeable(
z.object({
a: z.number(),
b: z.string(),
c: z.object({
d: z.array(z.object({
e: z.number().max(1),
f: z.boolean()
})).length(10)
})
})
)).toMatchInlineSnapshot
(`
"z.object({
a: z.number().optional(),
b: z.string().optional(),
c: z.object({
d: z.array(z.object({
e: z.number().max(1).optional(),
f: z.boolean().optional()
})).length(10).optional()
}).optional()
})"
`)
zx.deepPartialConverts an arbitrary zod schema into its "deeply-partial" form.
That just means that the schema will be traversed, and wrap all z.object
z.objectproperties with z.optionalz.optional.Options
zx.deepPartial's behavior is configurable at the typelevel via the defaults.typeleveloptions.typelevelproperty:defaults.typelevel
"semantic"(default): leave the schema untouched, but wrap it in a no-op interface (zx.deepPartial.Semantic) to make things explicitdefaults.typelevel
"applyToTypesOnly": apply the transformation to the schema's output type and wrap it in z.ZodTypez.ZodTypedefaults.typelevel
"preserveSchemaType":zx.deepPartialwill return what it got, type untouchedNote:
Make sure you understand the semantics of
deepPartialbefore you use this in production. There's a reason it was removed from zod proper. This library trusts users to do their due diligence to make sure they understand the tradeoffs.