-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Enhance ZodArray .min()
and .length()
Types
#2656
Conversation
✅ Deploy Preview for guileless-rolypoly-866f8a ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify site configuration. |
.min()
and .length()
Types
I dig the concept but this particular incarnation won't fly. That recursive alias can really hurt performance under the best of circumstances, and I'm sure there are many usages of Since this ultimately resolves to a tuple type I'd be more amenable to keeping separate from ZodArray. (In retrospect even Maybe a z.string().tuple(3);
// ZodTuple<[ZodString, ZodString, ZodString]> |
Closing to rethink |
@samchungy @colinhacks Any progress on this? I need this type type TypeINeed = [number, number];
type TypeItProduces = [number, ...number[]]; I've used this methonds, but none returned infered type as: {
rooms: z.array(z.number()).nonempty().min(2).max(2).length(2),
rooms: z.number().array().min(2).nonempty(),
rooms: z.number().array().min(2).max(2).nonempty(),
} Is there a way in the current version? |
Sounds like you're after a tuple rather than an array |
I've a usecase where I'm using length to ensure that I only have 8 elements in the array. Figured i should use tupples instead. However, I don't wanna wanna write those elements, 8 times in the array in my code (would be quite verbose) so i built this lil helper function to do that for me.
would it make sense to have an optional param as the second parameter to have this repeating feature ? wonder how people commonly use the tuples feature 🤔 |
Resolves #2658