array field infers strange errors object
See original GitHub issueHi =)
this kind of zod schema dont work as expected
const schema = z.object({
title: z
.string()
.regex(/^[A-Za-z0-9_]+$/, "wrong pattern")
.nonempty("Required"),
someArray: z.array(z.string().nonempty()).min(1)
});
Steps to reproduce the behavior:
-
- fill title input
-
- press submit
-
- fill array input
-
- press submit
-
- clear array input
- in console errors changes shape of field someArray from Object to Array
https://codesandbox.io/s/gifted-hopper-k4ndp?file=/src/App.tsx
Issue Analytics
- State:
- Created 2 years ago
- Reactions:2
- Comments:7 (4 by maintainers)
Top Results From Across the Web
Why Compiler cannot infer the object array type?
Because the types in the array aren't specific object - they are 3 different types that are all subclasses of object.
Read more >issue with clear array errors in FieldArray #1097 - GitHub
When "errors" is empty the array is not been removed in "errors" object. Steps to reproduce the behavior: remove value from the first...
Read more >Arrays | Elasticsearch Guide [8.5] | Elastic
In Elasticsearch, there is no dedicated array data type. Any field can contain zero or more values by default, however, all values in...
Read more >Arrays - The Modern JavaScript Tutorial
An array, just like an object, may end with a comma: let fruits = [ "Apple", "Orange", ... Let's say we want the...
Read more >10 Most Common Mistakes That PHP Developers Make - Toptal
As a result, when we go through the second foreach loop, “weird stuff” ... The reason is that, unlike arrays, PHP always passes...
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
@kerosan sorry for the late reply, I found the problem.
You’ve to update the
onChange
:Because
e.target.value
is""
when you clear the input and zod validate the following value:[""]
.@bluebill1049 Is that normal we can’t do the following:
onChange(undefined)
, seems not working withundefined
🤔Hope it solves your issue 😃
Hi @kerosan I’ll have a look tonight 😃