Skip to content

Superstruct: Array attribute types error an array of errors instead of an object for errors #160

@coreyjv

Description

@coreyjv

Describe the bug

When using superstruct resolver with an array field type the the error object is an array instead of an object per the React Hook Form documentation.

To Reproduce
Steps to reproduce the behavior:

  1. Go to https://codesandbox.io/s/competent-kalam-v98vd?file=/src/App.js
  2. Click on "Submit Query" button
  3. Observe the arrayField errors property is an array instead of an object. This is the unexpected behavior.
  4. Observe that nonArrayField errors property is an object as expected.

Expected behavior

Per the documentation the errors for a field should be an object with a message and type property and not an array.

Desktop (please complete the following information):

  • OS: MacOS 10.15.7
  • Browser: Firefox
  • Version 88.0b4

Additional context

In this instance it appears that parseErrorSchema produces an object like this:

  { "arrayField.0": { "message": "Expected one of `"John,"Jane"`, but received: "Bill"", "type": "enums" } }

which when passed to toNestError from @hookform/resovlers returns an Array

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions