Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it normal that a Tuple is valid if a value is empty ? #1693

Closed
nmeuni opened this issue Dec 14, 2022 · 1 comment
Closed

Is it normal that a Tuple is valid if a value is empty ? #1693

nmeuni opened this issue Dec 14, 2022 · 1 comment

Comments

@nmeuni
Copy link

nmeuni commented Dec 14, 2022

[Zod v.3.20.2]

Hello, I'm a in use case where I can have tuple like that: [<1 empty>, "toto"]
In this case the safeParse method return a success with ["toto"] in result.data. Is this the expected behavior ?
I found no "simple" way to make the parser return an error. (Maybe by using .refine or by creating a custom rule)

Code to reproduce in RunKit

  var z = require("zod")
  
  const test = []
  
  test[1] = "toto"
  
  const ZodTupleTest = z.tuple([z.number(), z.string()]);
  
  ZodTupleTest.safeParse(test)

That said, it's a very usefull lib ;)

colinhacks pushed a commit that referenced this issue Dec 24, 2022
* Add testcase - tuple as sparse array

* Destructure array to make .map() work properly - ZodTuple

* Make tuple as sparse array test more clear

* Add testcase - array as sparse array

* Destructure array to make .map() work properly - ZodArray
@JacobWeisenburger JacobWeisenburger added the closeable? This might be ready for closing label Dec 25, 2022
@JacobWeisenburger
Copy link
Collaborator

It looks like there was a merged PR fixing this. Can I close this issue?

@JacobWeisenburger JacobWeisenburger removed the closeable? This might be ready for closing label Dec 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants