Skip to content

Update type declarations for "Timezone-like" and "Calendar-like" parameters to support ZDT property bags #118

Closed
@justingrant

Description

@justingrant

The current public types for TimeZone.from look like this:

static from(timeZone: TimeZoneProtocol | string): Temporal.TimeZone | TimeZoneProtocol;

But the spec and the polyfill also accept a ZDT-like property bag too, per tc39/proposal-temporal#925. Specifically, they accept any object with a timeZone property and will use that property's value as the time zone, with one exception: per tc39/proposal-temporal#925 (comment), recursive bags like {timeZone: {timeZone: 'Asia/Tokyo'}} are disallowed.

Therefore, the declaration should also allow a { timeZone: TimeZoneProtocol | string } parameter type.

This issue tracks the work to:

  1. Figure out how to encode the "no recursive bags" in TS types. One possible way (not sure this will work) could be something like this:
type NoRecursiveTimeZones = { timeZone: { timeZone: never } };
. . .
  static from(timeZone: TimeZoneProtocol | string | { timeZone: TimeZoneProtocol } | NoRecursiveTimeZones): Temporal.TimeZone | TimeZoneProtocol; 
  1. Use that declaration throughout index.d.ts wherever TimeZone-like parameters are accepted
  2. Port the changes to proposal-temporal, and verify that the docs are correct for methods that accept a time zone parameter.
  3. Remove any now-unnecessary type casts, like the one @ptomato found in in https://github.com/js-temporal/temporal-polyfill/pull/109/files#r779978091.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions