Superstruct: Array attribute types error an array of errors instead of an object for errors
See original GitHub issueDescribe 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:
- Go to https://codesandbox.io/s/competent-kalam-v98vd?file=/src/App.js
- Click on “Submit Query” button
- Observe the
arrayField
errors property is an array instead of an object. This is the unexpected behavior. - 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
Issue Analytics
- State:
- Created 2 years ago
- Reactions:3
- Comments:6 (4 by maintainers)
Top Results From Across the Web
Errors - Superstruct
The error class that Superstruct uses for its validation errors. ... The key of the value when validating complex values like objects, arrays,...
Read more >Types - Superstruct
Custom types take validator functions that return either true/false or an array of StructFailure objects, in case you want to build more helpful...
Read more >FAQ - Superstruct
The object struct validates that a value matches a known object shape. Just like it's TypeScript counterpart, it does not allow unknown keys—this...
Read more >Handling Errors - Superstruct
The error thrown by Superstruct is always the first validation failure that was encountered, because this makes for convenient and simple logic in...
Read more >Introduction - Superstruct
import { assert, object, number, string, array } from 'superstruct' ... or nested objects, composing structs inside each other, returning errors instead of ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@jorisre there’s no solution that I’m aware of besides checking if the error object is an array and handling it accordingly.
@coreyjv Did you find a solution?