tc39 / proposal-intl-duration-format

https://tc39.es/proposal-intl-duration-format
MIT License
165 stars 18 forks source link

Throw RangeError instead of TypeError for format with non-object types #128

Closed Constellation closed 1 year ago

Constellation commented 2 years ago

We will integrate Temporal duration related changes in the future, and it will change the current format function's TypeError to RangeError. So, how about making it RangeError from the beginning? I think the rationale is that, "Intl.Duration#format can format Duration described as a String in a particular syntax, but in this spec, no syntax is accepted, so it is always throwing a RangeError".

var fmt = new Intl.DurationFormat('en');
fmt.format("");  // TypeError. But if Temporal is integrated, it will become RangeError
sffc commented 1 year ago

TG2 discussion: https://github.com/tc39/ecma402/blob/master/meetings/notes-2022-11-03.md#throw-rangeerror-instead-of-typeerror-for-format-with-non-object-types-128

Conclusion: RangeError, strings only.

FrankYFTang commented 1 year ago

We also need to change the following test to sync with it. @romulocintra

intl402/DurationFormat/prototype/formatToParts/invalid-arguments-throws.js
intl402/DurationFormat/prototype/format/invalid-arguments-throws.js