-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Intl.NumberFormat.prototype.format parameter type is too strict #52124
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
There is no undefined behavior in JS, only unintuitive behavior. To this end, many functions in JS perform automatic coercion like this but TS still considers it a type error to exploit it because it won't always do what you expect. See, e.g., #4002 and https://stackoverflow.com/questions/41750390/what-does-all-legal-javascript-is-legal-typescript-mean |
This issue has been marked 'Working as Intended' and has seen no recent activity. It has been automatically closed for house-keeping purposes. |
@RyanCavanaugh, would you reconsider this one? IMO, this is qualitatively different from regular number conversions in that the spec mandates that it be done without loss of precision, and there's no "correct" alternative way of accessing that behaviour. Current engines seem to deal with this:
|
I get this but in this case passing a string also results in distinct behaviour compared to regular number conversions, as documented, per @yseymour 's reference. Maybe the case for |
As others have stated, it's not a coercion in this API, it is specifically to support arbitrary-precision decimals (e.g. monetary numbers). It is very common to represent monetary numbers as strings in JSON APIs to avoid any precision loss and those can currently not be passed to the This was explicitly added as a feature in Intl NumberFormat v3: https://github.com/tc39/proposal-intl-numberformat-v3#interpret-strings-as-decimals-ecma-402-334 |
lib Update Request
I'm happy to open up a PR here, but wanted to open an issue first to discuss.
Configuration Check
My compilation target is
ES2017
and my lib isthe default
.Missing / Incorrect Definition
The types for
Intl.NumberFormat.prototype.format
require a number type, even though the TC39 spec does not require the input parameter to be a number and will handle string input.Sample Code
https://www.typescriptlang.org/play?#code/HYUw7gBAksAuA2A6AcgVwLYCMQCcBiA9jugIawAUA5CMALQCqAypQDQCUiAZkaRZQIwAGQZTYBuIA
Documentation Link
The text was updated successfully, but these errors were encountered: