import { z } from 'zod'
import { zx } from '@traversable/zod'
const Address = z.object({
street1: z.string(),
street2: z.optional(z.string()),
city: z.string(),
})
const addressEquals = zx.deepEqual(Address)
addressEquals(
{ street1: '221B Baker St', city: 'London' },
{ street1: '221B Baker St', city: 'London' }
) // => true
addressEquals(
{ street1: '221B Baker St', city: 'London' },
{ street1: '4 Privet Dr', city: 'Little Whinging' }
) // => false
zx.deepEqual.classic
Derive an in-memory "deep equal" function from a zod schema (v4, classic).
A "deep equal" function (see also,
Equal
) is similar to Lodash'sdeepEquals
function, except more performant, because when the shape of the values being compared is known ahead of time, we can optimize ahead of time, and only check what's necessary.Note that the "deepEqual function" generated by
zx.deepEqual
assumes that both values have already been validated. Passing unvalidated values to the function might result in undefined behavior.See also:
zx.deepEqual
zx.deepEqual.writeable