#Type Number is required but my number is too big.
31 messages · Page 1 of 1 (latest)
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.
can I sort of "fake" a type?
you could use a [bigint, bigint] to represent a mantissa and an exponent, for example
i have no idea what you mean by that
like can I tell typescript that it is a number, but it's actually a bigint?
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
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)
arithmatic operators cannot use mixed bigints and numbers, for example
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 
so faking it is possible, but I should avoid it
guess it's time to make a PR. Anyway, if I want to do what you said above, how would I do that?
I just need it to pass the compile right now for testing
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
hmm I see
will do! Thanks for the help and clarification!
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
