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

Remove exclusive from minLength, maxLength, after, and before schemas #992

Open
ssalbdivad opened this issue Jun 1, 2024 · 4 comments
Open

Comments

@ssalbdivad
Copy link
Member

In arktype we should still allow string>0, but instead of being parsed into {minLength: {rule: 0, exclusive: true}}, it should just become { minLength: 1 }. We can do the same for Date by incrementing the numeric value of the Date by one for exclusivity.

We need to keep exclusive for min/max because of non-integer values.

@TizzySaurus
Copy link

TizzySaurus commented Jun 1, 2024

One downside to this is we'd have to start doing type-level math to keep types accurate. Not the end of the world but it is nice having a way to represent without doing that, and I imagine more performant.

Out of interest, what's the motivation for removing the exclusive in the first place?

@ssalbdivad
Copy link
Member Author

@TizzySaurus Yeah that's right and it's a good insight. Especially problematic for Dates but probably just not that important to handle the distinction between whether a time range includes a particular millisecond or not at a type-level 😆

It is more accurate at runtime in terms of reducing equivalent types and cuts back on the clutter when defining signatures for chaining like this:

image

@TizzySaurus
Copy link

I see. That makes perfect sense, thanks!

@ssalbdivad
Copy link
Member Author

I did some initial work on this but it was a bit of a problem for some tests to not allow exclusive on length or Date schemas.

Worth revisiting this at some point for the extra normalization but not going to tackle this right away.

It should be handled at the schema=>inner parse level rather than the arktype level.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Backlog
Development

No branches or pull requests

2 participants