Skip to content

The options arg of Temporal.ZonedDateTime.prototype.toLocaleString() currently accepts "illegal" option timeZone #64227

Description

@Sector6759

⚙ Compilation target

ESNext

⚙ Library

ESNext

Missing / Incorrect Definition

toLocaleString(locales?: Intl.LocalesArgument, options?: Intl.DateTimeFormatOptions): string;

Sample Code

TypeScript allows the following code, when it should not.

Temporal.Now.zonedDateTimeISO("America/Chicago").toLocaleString(undefined, { timeZone: "Europe/Berlin" });

Result

Engine Error
JavaScriptCore TypeError: ZonedDateTime.toLocaleString does not accept a timeZone option; the ZonedDateTime's time zone is used
SpiderMonkey TypeError: can't set option timeZone when Temporal.ZonedDateTime.toLocaleString is used
V8 TypeError: Invalid time zone specified: America/Chicago

Documentation Link

According to MDN:

The timeZone option must not be provided, as it is automatically set to be the date-time's timeZoneId.

The type definitions should be changed to

declare namespace Temporal {
  // ...
  interface ZonedDateTimeToLocaleStringOptions extends Omit<Intl.DateTimeFormatOptions, "timeZone"> {}
  // ...
  interface ZonedDateTime {
    // ...
    toLocaleString(locales?: Intl.LocalesArgument, options?: ZonedDateTimeToLocaleStringOptions): string;
  }
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

BugA bug in TypeScriptDomain: lib.d.tsThe issue relates to the different libraries shipped with TypeScriptHelp WantedYou can do thisNeeds Human ReviewThis issue has a backlog check awaiting maintainer review.

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions