#Type Number is required but my number is too big.

31 messages · Page 1 of 1 (latest)

young vapor
#

If a value has type number defined, but my number is too big so it doesn't send the correct number, how do I send the correct number without modifying the definition number? I tried using BigInt, they both convert the type to something else rather than number.

livid gull
#

you kinda can't. js' number is an IEEE 754 double-precision floating-point number, it's designed to be less accurate at very large or very near-zero numbers so it can support a larger range.

#

you would need to use a different structure or type if you need more precision.

young vapor
#

can I sort of "fake" a type?

livid gull
#

you could use a [bigint, bigint] to represent a mantissa and an exponent, for example

livid gull
young vapor
livid gull
#

oh, you can do that, yeah. but that's a really big footgun you're holding.

#

you're not supposed to for multiple reasons

#

lying to the type system means the type system will be feeding that lie back to you

young vapor
#

changing the typing in my project would require a very long time to get approved, I just want to get simply input the ID (the number I am trying to send)

livid gull
#

arithmatic operators cannot use mixed bigints and numbers, for example

young vapor
# livid gull IDs should be strings

Yeah I know string would be better, it's a GET request so everything is going to be sent in string anyway. I have no idea why they set it to number mel_cry

young vapor
livid gull
#

it's not really faking the type

#

it's just lying

young vapor
#

I just need it to pass the compile right now for testing

livid gull
#

yeah no just use numbers if the ids are already numbers

#

using bigints won't really help you

#

PR to have them be strings instead

#

assertions are how you would do it if you really want to but it's just a whole landmine of footguns. just don't do it.

#

of course, i can't stop you, but it is a horrible idea and i hope i can dissuade you

#

assertions do have their usecases, but a disjoint assertion from number to bigint will more than likely create more problems than it solves

young vapor
livid gull
#

anyways as a closing note; "faking" types is never a solution to typescript's type issues. assertions are used to inform ts of things it can't infer by itself. asserting to lie will just cause errors, or worse, bugs, at runtime.

#

errors exist so bugs don't. a clear statement with a stacktrace is much easier to debug than a small change in behavior, and static type errors make it easier because you don't need to wait for the scenario to occur

young vapor
#

alright, I see why it's a bad thing to do. Guess I should work on other parts before my PR get accepted