arktype icon indicating copy to clipboard operation
arktype copied to clipboard

Throw ParseError on negative length constraint

Open TizzySaurus opened this issue 1 year ago • 0 comments

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 avatar May 26 '24 00:05 TizzySaurus