-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Stricter Array Types #2658
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
Comments
If this isn't desirable I can hide the type changes behind .nonempty() eg. When you use .nonempty() and .min() it will produce the stricter type |
@samchungy 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? |
Going to close this as there doesn't seem to be a performant way to achieve this. Also I hate the ecoaystem's support of this in general with .map .filter etc as it stands right now |
Uh oh!
There was an error while loading. Please reload this page.
Hey crew!
We rely on noUncheckedIndexedAccess on our repos so we rely on nonempty array types.
This makes enforcing array type lengths very important.
This proposes enhancements to
min
andlength
checks to create even more accurate types which can work well withnoUncheckedIndexedAccess
.We could type the following
But that would require a little bit of rework to pipe min and max cardinality around and probably isn't all that helpful in general.
The text was updated successfully, but these errors were encountered: