@traversable/schema
    Preparing search index...
    • Derive a "deep equal" function from a TypeBox schema.

      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 box.deepEqual assumes that both values have already been validated. Passing unvalidated values to the function might result in undefined behavior.

      Type Parameters

      • T extends TSchema

      Parameters

      • schema: T

      Returns Type.Equal<(T & { params: [] })["static"]>

      import * as T from '@sinclair/typebox'
      import { deepEqual } from '@traversable/typebox'

      const addressEquals = deepEqual(
      T.Object({
      street1: T.String(),
      street2: T.Optional(T.String()),
      city: T.String(),
      })
      )

      addressEquals(
      { street1: '221 Baker St', street2: '#B', city: 'London' },
      { street1: '221 Baker St', street2: '#B', city: 'London' },
      ) // => true

      addressEquals(
      { street1: '221 Baker St', street2: '#B', city: 'London' },
      { street1: '4 Privet Dr', city: 'Little Whinging' },
      ) // => false