@traversable/schema
    Preparing search index...

    Function deepEqual

    • Derive a "deep equal" function from a zod schema (v4, classic).

      A "deep equal" function" (see also, Equal) is similar to lodash's isEqual 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 deep equal 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:

      Type Parameters

      • T extends $ZodType<unknown, unknown, $ZodTypeInternals<unknown, unknown>>

      Parameters

      • type: T

      Returns Type.Equal<output<T>>

      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
    Index

    Properties

    classic: <
        T extends
            | $ZodType<unknown, unknown, $ZodTypeInternals<unknown, unknown>>
            | ZodType<unknown, unknown, $ZodTypeInternals<unknown, unknown>>,
    >(
        type: T,
    ) => Type.Equal<output<T>>

    Type declaration

      • <
            T extends
                | $ZodType<unknown, unknown, $ZodTypeInternals<unknown, unknown>>
                | ZodType<unknown, unknown, $ZodTypeInternals<unknown, unknown>>,
        >(
            type: T,
        ): Type.Equal<output<T>>
      • Derive an in-memory "deep equal" function from a zod schema (v4, classic).

        A "deep equal" function (see also, Equal) is similar to Lodash's deepEquals 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:

        Type Parameters

        • T extends
              | $ZodType<unknown, unknown, $ZodTypeInternals<unknown, unknown>>
              | ZodType<unknown, unknown, $ZodTypeInternals<unknown, unknown>>

        Parameters

        • type: T

        Returns Type.Equal<output<T>>

        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
    unfuzzable: [
        "promise",
        "transform",
        "custom",
        "default",
        "prefault",
        "promise",
        "success",
        "never",
        "unknown",
        "any",
        "nonoptional",
        "catch",
        "file",
    ]
    writeable: <
        T extends
            | $ZodType<unknown, unknown, $ZodTypeInternals<unknown, unknown>>
            | ZodType<unknown, unknown, $ZodTypeInternals<unknown, unknown>>,
    >(
        type: T,
        options?: Options,
    ) => string

    Type declaration

      • <
            T extends
                | $ZodType<unknown, unknown, $ZodTypeInternals<unknown, unknown>>
                | ZodType<unknown, unknown, $ZodTypeInternals<unknown, unknown>>,
        >(
            type: T,
            options?: Options,
        ): string
      • Derive a writeable (stringified) "deep equal" function from a zod schema (v4, classic).

        A "deep equal" function (see also, Equal) is similar to Lodash's isEqual 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 deep equal function generated by zx.deepEqual assumes that both values have already been validated. Passing unvalidated values to the function might result in undefined behavior.

        zx.deepEqual.writeable accepts an optional configuration object as its second argument; documentation for those options are available via hover on autocompletion.

        See also:

        Type Parameters

        • T extends
              | $ZodType<unknown, unknown, $ZodTypeInternals<unknown, unknown>>
              | ZodType<unknown, unknown, $ZodTypeInternals<unknown, unknown>>

        Parameters

        • type: T
        • Optionaloptions: Options

        Returns string

        import { z } from 'zod'
        import { zx } from '@traversable/zod'

        const deepEqual = zx.deepEqual.writeable(
        z.object({
        street1: z.string(),
        street2: z.optional(z.string()),
        city: z.string(),
        }),
        { typeName: 'Address' }
        )

        console.log(deepEqual)
        // =>
        // type Address = { street1: string; street2?: string; city: string; }
        // function deepEqual(x: Address, y: Address) {
        // if (x === y) return true;
        // if (x.street1 !== y.street1) return false;
        // if (x.street2 !== y.street2) return false;
        // if (x.city !== y.city) return false;
        // return true;
        // }