Skip to content

Typed Object Maps

If you need "an object whose keys are dynamic, but whose values all follow one contract", use values:

javascript
const schema = createSchema({
  fieldErrors: {
    type: 'object',
    values: {
      type: 'string',
      minLength: 1
    }
  }
})

That means:

  • the value must be a plain object
  • keys remain dynamic
  • every value is validated with the provided field definition

values can point to either:

  • an inline field definition such as { type: 'string', minLength: 1 }
  • a child Schema instance when every dynamic value should itself be a structured object contract

When values points to a child object schema, each dynamic value is validated in replace mode for the same reason array object items are: each value is treated as a complete object at that key.

GPL-3.0-only