Skip to content

Update TS types of TimeZone-like/Calendar-like params to match spec and polyfill #126

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 4, 2022

Conversation

justingrant
Copy link
Contributor

Extends TS tsupport for property-bag form of Calendar-like and TimeZone-like params in Temporal methods. Fixes #118

Also allows Temporal.Calendar instances to be used in the Intl.DateTimeFormatOptions type. (Previously only string IDs were allowed.) Fixes #124.

Note that fixing tc39/proposal-temporal#2005 will further extend the types that can be passed into the calendar and timeZone properties of Intl.DateTimeFormatOptions. But that requires a spec change and polyfill code change, so in this PR we'll only extend Intl.DateTimeFormatOptions to what's supported by the current spec and polyfill.

Extends TS tsupport for property-bag form of Calendar-like and
TimeZone-like params in Temporal methods.
Fixes js-temporal#118

Also allows `Temporal.Calendar` instances to be used in the
`Intl.DateTimeFormatOptions` type. (Previously only string IDs were
allowed.
Fixes js-temporal#124.

Note that fixing tc39/proposal-temporal#2005
will further extend the types that can be passed into the `calendar` and
`timeZone` properties of `Intl.DateTimeFormatOptions`. But that requires
a spec change and polyfill code change, so in this commit we'll only
extend `Intl.DateTimeFormatOptions` to what's supported by the current
spec and polyfill.
Copy link
Contributor

@ptomato ptomato left a comment

Choose a reason for hiding this comment

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

LGTM, a couple of questions though:

With the type updates in this PR, a few type casts are not needed. See
https://github.com/js-temporal/temporal-polyfill/pull/109/files#r780638159
for more context.
@justingrant
Copy link
Contributor Author

Good catch! Thanks for remembering that. Fixed now in latest commit. (Both the timezone and the calendar cast could be removed.)

  • does this encode the "no recursive property bags" rule or is that coming in a follow-up?

I couldn't figure out how to encode that in TS types. Tried a few ways to do it, none of them seemed to work. So leaving that for someone with better TypeScript Fu than me.

@ptomato
Copy link
Contributor

ptomato commented Feb 4, 2022

leaving that for someone with better TypeScript Fu than me.

Well, certainly not me. I salute whoever it is!

@justingrant
Copy link
Contributor Author

  • does this encode the "no recursive property bags" rule or is that coming in a follow-up?

I couldn't figure out how to encode that in TS types. Tried a few ways to do it, none of them seemed to work. So leaving that for someone with better TypeScript Fu than me.

Actually, I take that back. If an object bag is used, then its timeZone or calendar property, respectively, must be string | TimeZoneProtocol or string | CalendarProtocol. The two protocol types already have timeZone?: never and calendar?: never properties defined which should disallow recursion. It's not perfect; a timeZone: undefined property will pass TS, but any non-undefined value will cause a compile error. I tried making those never properties non-optional, but this broke other code so I figured we can just take the W with the current types.

@justingrant justingrant merged commit 9d54c64 into js-temporal:main Feb 4, 2022
justingrant added a commit to justingrant/proposal-temporal that referenced this pull request Feb 4, 2022
justingrant added a commit to tc39/proposal-temporal that referenced this pull request Feb 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants