Skip to content

Intl.ResolvedDateTimeFormatOptions is missing properties #45420

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

Closed
BPScott opened this issue Aug 11, 2021 · 8 comments · Fixed by #45905
Closed

Intl.ResolvedDateTimeFormatOptions is missing properties #45420

BPScott opened this issue Aug 11, 2021 · 8 comments · Fixed by #45905
Labels
Bug A bug in TypeScript Domain: lib.d.ts The issue relates to the different libraries shipped with TypeScript Help Wanted You can do this
Milestone

Comments

@BPScott
Copy link

BPScott commented Aug 11, 2021

lib Update Request

Configuration Check

My compilation target is ES2020 and my lib is the default.

Missing / Incorrect Definition

Intl.ResolvedDateTimeFormatOptions - the type returned by calling DateTimeFormat's resolvedOptions method - appears to be missing the following properties:

  • dateStyle
  • timeStyle
  • dayPeriod
  • hourCycle
  • fractionalSecondDigits

It looks like these items (along with calendar and numberingSystem) were added to es2020.intl.d.ts's DateTimeFormatOptions however they were never added to ResolvedDateTimeFormatOptions.

It seems that calendar and numberingSystem are both present in es5.d.ts's ResolvedDateTimeFormatOptions. Because of this I am unsure if the absent options should be added to ResolvedDateTimeFormatOptions in es5.d.ts or es2020.d.ts.

https://tc39.es/ecma402/#table-datetimeformat-resolvedoptions-properties is the spec table of possible returned properties

Sample Code

Sample TS playground

console.log(new Intl.DateTimeFormat('en-US', { dateStyle: 'short' }).resolvedOptions().dateStyle)
console.log(new Intl.DateTimeFormat('en-US', { timeStyle: 'long' }).resolvedOptions().timeStyle)

console.log(new Intl.DateTimeFormat('en-US', { dayPeriod: 'narrow' }).resolvedOptions().dayPeriod)
console.log(new Intl.DateTimeFormat('en-US', { timeStyle: 'long', hourCycle:'h24' }).resolvedOptions().hourCycle)

console.log(new Intl.DateTimeFormat('en-US', { fractionalSecondDigits: 1 }).resolvedOptions().fractionalSecondDigits)

The above lines throw type errors saying the various properies on resolvedOptions do not exist

Documentation Link

https://tc39.es/ecma402/#table-datetimeformat-resolvedoptions-properties

@IllusionMH
Copy link
Contributor

IllusionMH commented Aug 12, 2021

Duplicate of #42577 which itself is duplicate of other issues.
Not a duplicate of linked issue

@BPScott
Copy link
Author

BPScott commented Aug 12, 2021

This issue looks to be more thorough than #42577 - which does not mention the dayPeriod or fractionalSecondDigits.

#42577 has been marked as a duplicate of #35865 / #34399. In both cases that appears to be an incorrect diagnosis, as both of those issues are about improvements to DateTimeFormatOptions, NOT ResolvedDateTimeFormatOptions.

@IllusionMH
Copy link
Contributor

Yes, you are correct. Read by diagonal and missed that ResolvedDateTimeFormatOptions were not updated to match other options added to options.

Also looks like it's tricky question in which file definitions should go as #42945 tries to "move" (in that case just removing) some of this properties of DateTimeFormatOptions to further versions.

@RyanCavanaugh RyanCavanaugh added Bug A bug in TypeScript Domain: lib.d.ts The issue relates to the different libraries shipped with TypeScript Help Wanted You can do this labels Aug 13, 2021
@RyanCavanaugh RyanCavanaugh added this to the Backlog milestone Aug 13, 2021
orta added a commit to orta/TypeScript that referenced this issue Aug 30, 2021
orta pushed a commit that referenced this issue Sep 8, 2021
* Import of Intl.Locale from #39664

* Handle updating es2020.intl and add es2021 for new DateTimeFormatOptions options - re: #39664

* Extends DateTimeFormatOptions for new Intl APIs - re: #45420

* Handle migrating Intl.NumberFormat.formatToParts to es2018 (keeping esnext.intl around)

* Adds Intl.DisplayNames to es2020 - re: #44022

* Remove attributes added in es2021 from es2020 - re: #42944

* Add a reference to es2021 in the command line parser

* Adds some docs about the lib files

* Baselines

* Allow undefined in Intl inputs to allow for ergonomic usage of exactOptionalPropertyTypes - see #45652

* Adds some tests covering the APIs

* Apply suggestions from code review

Co-authored-by: Nathan Shively-Sanders <[email protected]>

* Handle PR feedback

* More review improvements

Co-authored-by: Nathan Shively-Sanders <[email protected]>
@orta
Copy link
Contributor

orta commented Sep 8, 2021

I'm reasonably sure I've got all these covered and merged into main with in #45647 - should be available in 4.5

@orta orta closed this as completed Sep 8, 2021
@BPScott
Copy link
Author

BPScott commented Sep 8, 2021

Heya @orta,

I'm not sure if I'm reading that PR correctly but it looks like DateTimeFormatOptions was updated but I can't see any adjustments to ResolvedDateTimeFormatOptions, or any places where the return interface of resolvedOptions() got changed to something else.

@BPScott
Copy link
Author

BPScott commented Sep 16, 2021

Ping @orta, I've just tried on the nightly build playground and it still raises type errors.

I don't think this issue has been resolved as the types of ResolvedDateTimeFormatOptions don't seem to have been updated

@orta orta reopened this Sep 16, 2021
@orta
Copy link
Contributor

orta commented Sep 16, 2021

Yep, I agree 👍🏻

@BPScott
Copy link
Author

BPScott commented Sep 23, 2021

Thanks @orta <3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Domain: lib.d.ts The issue relates to the different libraries shipped with TypeScript Help Wanted You can do this
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants