microsoft / TypeScript

TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
https://www.typescriptlang.org
Apache License 2.0
100.87k stars 12.47k forks source link

Number.prototype.toFixed, Number.prototype.toExponential,Number.prototype.toPrecision comments error #59653

Open purple-force opened 2 months ago

purple-force commented 2 months ago

🔎 Search Terms

is:issue Number toFixed

🕗 Version & Regression Information

⏯ Playground Link

No response

💻 Code

// Your code here

🙁 Actual behavior

https://github.com/microsoft/TypeScript/blob/52395892e0c4ee8a22b4fa6190bad46d81e66651/src/lib/es5.d.ts#L550 https://github.com/microsoft/TypeScript/blob/52395892e0c4ee8a22b4fa6190bad46d81e66651/src/lib/es5.d.ts#L556 https://github.com/microsoft/TypeScript/blob/52395892e0c4ee8a22b4fa6190bad46d81e66651/src/lib/es5.d.ts#L562

🙂 Expected behavior

The right range is 0 to 100 for toFixed and toExponential, 1 to 100 for toPrecision.

Additional information about the issue

No response

ehoogeveen-medweb commented 2 months ago

Spec links:

For each case, the valid range is given in step 5.

ehoogeveen-medweb commented 2 months ago

It looks like this was changed here and first appeared in ES2018 (but I don't know if the comment can be versioned or if you'd want it to be).

purple-force commented 2 months ago

Since this definition is used by later version es spec and many developers don't know the history, maybe following the spec is a better choice?