A
arktype14mo ago
OnkelTem

ParseError: '3.0' was parsed as a number but could not be narrowed to a literal value.

I'm not sure yet, where does this come from, but does it say anything to you?
/projects/custom/hfl/node_modules/arktype/dist/cjs/utils/errors.js:25
throw new ParseError(message);
^
ParseError: '3.0' was parsed as a number but could not be narrowed to a literal value. Avoid unnecessary leading or trailing zeros and other abnormal notation
at throwParseError (/projects/custom/hfl/node_modules/arktype/dist/cjs/utils/errors.js:25:11)
at parseWellFormed (/projects/custom/hfl/node_modules/arktype/dist/cjs/utils/numericLiterals.js:5
...
/projects/custom/hfl/node_modules/arktype/dist/cjs/utils/errors.js:25
throw new ParseError(message);
^
ParseError: '3.0' was parsed as a number but could not be narrowed to a literal value. Avoid unnecessary leading or trailing zeros and other abnormal notation
at throwParseError (/projects/custom/hfl/node_modules/arktype/dist/cjs/utils/errors.js:25:11)
at parseWellFormed (/projects/custom/hfl/node_modules/arktype/dist/cjs/utils/numericLiterals.js:5
...
11 Replies
OnkelTem
OnkelTemOP14mo ago
Ok, here is a type:
const input$ = type({
speed: '0.1<=number<=3.0',
})
const input$ = type({
speed: '0.1<=number<=3.0',
})
I take it I use a wrong syntax? Changing 3.0 to 3 seems to fix the issue:
const input$ = type({
speed: '0.1<=number<=3',
})
const input$ = type({
speed: '0.1<=number<=3',
})
Hm, dunno why it makes a difference
ssalbdivad
ssalbdivad14mo ago
Well to be fair the error message is pretty good 😛 "'3.0' was parsed as a number but could not be narrowed to a literal value. Avoid unnecessary leading or trailing zeros and other abnormal notation" This restriction has to do with how TS infers numeric literals, it can't accurately infer 3.0 since it's redundant to add .0
OnkelTem
OnkelTemOP14mo ago
But yuck 🙂 Be like that. Thinking that 3.0 is abnormal hahah
ssalbdivad
ssalbdivad14mo ago
I could probably remove it here TBH, it's really only important for static inference it was just a 1:1 thing and it doesn't matter for bounds anyways
OnkelTem
OnkelTemOP14mo ago
And I wrote 3.0 automatically, because I wrote 0.1 🙂 Same precision, university education you know
ssalbdivad
ssalbdivad14mo ago
Yeah I get it, I think I could remove it. Personally I would not write it like that because I find having exactly one representation of each unique value more important than matching decimal places but I did drop out of school so maybe that's why 😛
OnkelTem
OnkelTemOP14mo ago
You were boring there? 🙂
ssalbdivad
ssalbdivad14mo ago
Something like that
OnkelTem
OnkelTemOP14mo ago
hah
ssalbdivad
ssalbdivad14mo ago
I did update this to no longer fail in beta (the numeric literal parsing is only done for a standalone number literal) That should have been the behavior anyways since it works that way on the types so you can add dynamic bounds
OnkelTem
OnkelTemOP14mo ago
👍🏻
Want results from more Discord servers?
Add your server