Skip to content

types: require timeZone property in ZonedDateTimeLike (#352) - #376

Closed
cyber-atharv wants to merge 1 commit into
js-temporal:mainfrom
cyber-atharv:fix/zoneddatetime-from-require-timezone
Closed

cyber-atharv wants to merge 1 commit into
js-temporal:mainfrom
cyber-atharv:fix/zoneddatetime-from-require-timezone

Conversation

@cyber-atharv

Copy link
Copy Markdown

Description

Closes #352.

In index.d.ts, ZonedDateTimeLike previously defined timeZone?: TimeZoneLike as optional.
However, when calling Temporal.ZonedDateTime.from() with a property bag, the TC39 specification (ToTemporalZonedDateTime) requires the timeZone property. At runtime, omitting timeZone throws:

TypeError: required property 'timeZone' missing or undefined

Changes

  1. ZonedDateTimeLike: Made timeZone: TimeZoneLike required, reflecting runtime requirements for from(), compare(), equals(), until(), since(), and relativeTo.
  2. ZonedDateTime.prototype.with: Typed parameter as Omit<ZonedDateTimeLike, 'timeZone'> so that partial date/time modifications (e.g. zdt.with({ year: 2027 })) remain valid without requiring timeZone, while correctly preventing callers from passing timeZone (which throws TypeError: with() does not support a timeZone property at runtime).

Verification

  • Run Prettier check: prettier index.d.ts --check (Passed)
  • Run type check on ambient definitions: tsc index.d.ts --noEmit --types --strict --lib ESNext (Passed)
  • Run full project type check: tsc --noEmit (Passed)
  • Validated negative test case: Calling Temporal.ZonedDateTime.from({ year: 2026, month: 1, day: 1 }) now fails TypeScript type-checking with:
    Property 'timeZone' is missing in type '{ year: number; month: number; day: number; }' but required in type 'ZonedDateTimeLike'
  • Validated positive test cases: Calling Temporal.ZonedDateTime.from({ year: 2026, month: 1, day: 1, timeZone: 'UTC' }) and zdt.with({ year: 2027 }) compile cleanly.

@ptomato

ptomato commented Oct 19, 2026

Copy link
Copy Markdown
Contributor

Thanks for the PR!
We're most likely going to pull in the official TypeScript types for the next release, so we're not going to continue developing these. If the types in the TypeScript repo don't handle this, then please submit the change there.

@ptomato ptomato closed this Oct 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TypeScript: ZonedDateTime.from() doesn't require timeZone property, but runtime throws error

2 participants