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

Throw ParseError on negative length constraint #979

Open
TizzySaurus opened this issue May 26, 2024 · 0 comments
Open

Throw ParseError on negative length constraint #979

TizzySaurus opened this issue May 26, 2024 · 0 comments
Assignees

Comments

@TizzySaurus
Copy link

Report a bug

πŸ”Ž Search Terms

negative length constraint, max length, min length

🧩 Context

  • ArkType version: 2.0.0-dev.16
  • TypeScript version (5.1+): 5.4.5
  • Other context you think may be relevant (JS flavor, OS, etc.): N/A

πŸ§‘β€πŸ’» Repro

ArkType currently allows negative length constraints for both strings and arrays, which doesn't really make sense. IMO negative length constraints should be entirely disallowed, but at a minimum it shouldn't allow setting the maximum length to a negative number since no value will ever satisfy this.

Current Behaviour

import { type } from "arktype";

const t = type("string[]<-1");
console.log(t.json) // {sequence: 'string',  proto: 'Array',  minLength: { exclusive: true, rule: -1 }}

Expected Behaviour

import { type } from "arktype";

const t = type("string[]<-1");
console.log(t.json) // errors, stating that length constraint cannot be negative
@TizzySaurus TizzySaurus added the bug Something isn't working label May 26, 2024
@ssalbdivad ssalbdivad removed the bug Something isn't working label May 28, 2024
@ssalbdivad ssalbdivad changed the title ArkType allows restricting to negative lengths Throw ParseError on negative length constraint May 28, 2024
@TizzySaurus TizzySaurus changed the title Throw ParseError on negative length constraint ArkType allows negative length constraints Jun 2, 2024
@TizzySaurus TizzySaurus changed the title ArkType allows negative length constraints Throw ParseError on negative length constraint Jun 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Backlog
Development

No branches or pull requests

2 participants