does arktype understand "minimum 0 but not -0"?
in zod, even if you put
.nonnegative
it will still accept negative zero. would the same happen with AT?
7 Replies
I tried this in the Arktype playground:
and it passed
so presumably yes
https://arktype.io/playground?code=import%2520%257B%2520type%2520%257D%2520from%2520%2522arktype%2522%250A%250Aconst%2520Thing%2520%253D%2520type%28%257B%250A%2509name%253A%2520%2522string%2522%252C%250A%2509%2522versions%253F%2522%253A%2520%2522%28number%2520%257C%2520string%29%255B%255D%2522%250A%257D%29%250A%250Aconst%2520out%2520%253D%2520Thing%28%257B%250A%2520%2520%2520%2520name%253A%2520%2522TypeScript%2522%252C%250A%2520%2520%2520%2520versions%253A%2520%255B%25225.8.2%2522%252C%25206%252C%25207n%255D%250A%257D%29%250A
fwiw it's pretty easy to fix;
Though @ssalbdivad might want to know that the error message for
-0
was must be a positive number (was 0)
which is mildly misleading because it was -0
not that I blame you (-0).toString()
is "0"
it's a bit on-the-line what to do here
In fairness the exact code I did was
number >= 0
and -0 >= 0
is true
the IEEE-754 spec says that
0.0
and -0.0
are considered equal (last I checked)
rightyeah they are
it's why I had to use
Object.is
in the narrow
to make -0
an error but not 0
otherwise I'd just have done data > 0 || data === 0
but in reality that'd allow -0
first time I've seen a legitimate use case tbhyeah, cool, thanks
i've run into issues with zod not differentiating btwn 0 and -0 before, i think it had to do with serialization/deserialization
would be nice to invert control somehow and let devs decide what it means for 2 numbers to be equivalent