Skip to content

Editorial: Update GetOption to throw a TypeError when a required option is missing - #1068

Merged
gibson042 merged 3 commits into
tc39:mainfrom
gibson042:2026-05-getoption-typeerror-if-missing-required
Jun 11, 2026
Merged

Editorial: Update GetOption to throw a TypeError when a required option is missing#1068
gibson042 merged 3 commits into
tc39:mainfrom
gibson042:2026-05-getoption-typeerror-if-missing-required

Conversation

@gibson042

Copy link
Copy Markdown
Member

TypeError rather than RangeError is in better alignment with other parts of the spec where a required parameter or option is missing:

Fortunately, this change is editorial because no current site calls GetOption with default ~required~, although I expect proposals like Amount to do so.

…on is missing

TypeError rather than RangeError is in better alignment with other parts of the
spec where a required parameter or option is missing:
* [ECMA-262 GroupBy](https://tc39.es/ecma262/#sec-groupby)
* [ECMA-262 Object static functions](https://tc39.es/ecma262/#sec-properties-of-the-object-constructor)
* [ECMA-262 RegExp.escape](https://tc39.es/ecma262/#sec-regexp.escape)
* [ECMA-262 Array.prototype.every](https://tc39.es/ecma262/#sec-array.prototype.every) et al.
  * Also {Map,Set}.prototype.{forEach,getOrInsertComputed}
* [ECMA-262 Uint8Array static methods](https://tc39.es/ecma262/#sec-additional-properties-of-the-uint8array-constructor)
* ECMA-262 Set.prototype.{difference,intersection,union,...}
* ECMA-262
  [WeakMap methods](https://tc39.es/ecma262/#sec-properties-of-the-weakmap-prototype-object)
  and
  [WeakSet methods](https://tc39.es/ecma262/#sec-properties-of-the-weakset-prototype-object)
* [ECMA-262 Promise](https://tc39.es/ecma262/#sec-promise-constructor)
* [ECMA-262 Reflect functions](https://tc39.es/ecma262/#sec-reflect-object)
* [Intl.DateTimeFormat.prototype.{formatRange,formatRangeToParts}](https://tc39.es/ecma402/#sec-intl.datetimeformat.prototype.formatRange)
  * Also [Intl.NumberFormat.prototype.{formatRange,formatRangeToParts}](https://tc39.es/ecma402/#sec-intl.numberformat.prototype.formatrange)
    and
    [Intl.PluralRules.prototype.selectRange](https://tc39.es/ecma402/#sec-intl.pluralrules.prototype.selectrange)
* [Intl.DisplayNames](https://tc39.es/ecma402/#sec-Intl.DisplayNames) (which
  should actually be updated to
  `Let _type_ be ? GetOption(_options_, *"type"*, ~string~, « *"language"*, *"region"*, *"script"*, *"currency"*, *"calendar"*, *"dateTimeField"* », ~required~).`)
* [Intl.DurationFormat.prototype.{format,formatToParts}](https://tc39.es/ecma402/#sec-Intl.DurationFormat.prototype.format)
* [Intl.Locale](https://tc39.es/ecma402/#sec-Intl.Locale)
* [SetNumberFormatUnitOptions](https://tc39.es/ecma402/#sec-setnumberformatunitoptions)
  as exercised by e.g. `new Intl.NumberFormat("en", { style: "currency" })` and
  `new Intl.NumberFormat("en", { style: "unit" })`

Fortunately, this change is editorial because no current site calls GetOption
with _default_ ~required~, although I expect proposals like
[Amount](https://github.com/tc39/proposal-amount) to do so.
@gibson042
gibson042 requested review from ryzokuken and sffc May 18, 2026 04:44

@anba anba left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a normative change for Temporal:

// Currently spec'ed to throw a RangeError.
new Temporal.ZonedDateTime(0n, "UTC").getTimeZoneTransition({})

The required option was added to GetOption in #687.

@ryzokuken ryzokuken added editorial Involves an editorial fix needs consensus labels May 19, 2026
@gibson042

Copy link
Copy Markdown
Member Author

The required option was added to GetOption in #687.

Yes, I remember that... most of #687 was subsequently reverted in #822, but not that part.

This is a normative change for Temporal:

// Currently spec'ed to throw a RangeError.
new Temporal.ZonedDateTime(0n, "UTC").getTimeZoneTransition({})

AFAICT, it's actually not... I don't see any uses of GetOption in #1044, and tc39/ecma262#3759 is no longer introducing GetOption to ECMA-262, instead having its own GetTemporalUnitValuedOption for reading unit/smallestUnit/largestUnit properties and GetDirectionOption for handling direction in Temporal.ZonedDateTime.prototype.getTimeZoneTransition (the latter being responsible for the above RangeError).

But you're right to single out Temporal here, and it is odd that it diverges in this way. It seems like the Temporal RangeErrors were introduced without scrutiny in ToSmallestTemporalUnit by tc39/proposal-temporal#886 (where they were appropriate for «If disallowedUnits contains smallestUnit» but not for «If smallestUnit is "not present"») and Temporal.Duration.prototype.total by tc39/proposal-temporal#1064 (later moved into ToTemporalDurationTotalUnit by tc39/proposal-temporal#1599), carried forward without comment into GetTemporalUnit by tc39/proposal-temporal#2248 , rolled into GetOption by #687 , and then Temporal subsequently abandoned GetOption but kept the behavior.

I'm still very much in favor of having the more standard behavior here, and will see what can be done to bring Temporal in line (although it looks like there is some test262 coverage:

@anba

anba commented May 20, 2026

Copy link
Copy Markdown
Contributor

AFAICT, it's actually not... I don't see any uses of GetOption in #1044, [...]

Ah, I see. I didn't know that this changed in the ECMA262 spec PR when compared to what's on https://tc39.es/proposal-temporal.

@gibson042

gibson042 commented May 20, 2026

Copy link
Copy Markdown
Member Author

Ah, I see. I didn't know that this changed in the ECMA262 spec PR when compared to what's on https://tc39.es/proposal-temporal.

Yeah, we're in an awkward state right now where the source of truth for Temporal is at tc39/ecma262#3759 (and its ECMA-402 sibling at #1044 ).

@sffc sffc moved this to Priority Issues in ECMA-402 Meeting Topics May 27, 2026
@sffc sffc added the s: discuss Status: TG2 must discuss to move forward label May 27, 2026
Comment thread spec/displaynames.html Outdated

@sffc sffc left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, if a required option is missing, it is a TypeError. If Temporal is doing something different, then it is a bug in Temporal.

@gibson042
gibson042 merged commit 00372a1 into tc39:main Jun 11, 2026
2 checks passed
@sffc sffc moved this from Priority Issues to Previously Discussed in ECMA-402 Meeting Topics Jul 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

editorial Involves an editorial fix needs consensus s: discuss Status: TG2 must discuss to move forward

Projects

Status: Previously Discussed

Development

Successfully merging this pull request may close these issues.

4 participants