-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
Stricter type for ES5 Intl, redefine ES2020 intl #42134
Conversation
Thanks! This looks good to me 👍🏻 |
@orta this should be revised/reverted. List of numbering system & calendar are NOT part of the ECMA402 spec. They conform to Unicode Locale Identifier semantic restriction, but the list can change every CLDR version which is separate from ECMA402. Reference of failure upstream: formatjs/formatjs#2616 |
@longlho Can't TS keep up with CLDR versions regardless? |
no because every browser version potentially ships with a different CLDR/libicu version. The release cadence is different. The spec also intentionally does not rely on this except for things like:
An implementation can be spec-compliant if shipped with a newer/older CLDR version. |
@longlho I'm not seeing why this needs a revert. We can update this file out-of-band to include whatever the largest current list is without loss of correctness relative to just |
So the problem is I can ship an implementation with Listing it here in TS suggests that those are only valid values and others are not while in reality, it is indeed just a string of a specific semantic and API user should validate against calendar support. |
The es5 change is ok though, because the spec dictates that if you pass in an invalid option like |
Make sense. From a practical perspective, is this a thing that happens with regularity, or is it worth catching a subtle typo like |
Hmm I can see the argument for typo but I think at the end of the day you'd still need to manually do like |
This has been merged for six weeks without visible complaint from user code, so I'm willing to let this go out in 4.2 and revert if we find people in the wild hitting it if the problem is that it's only possibly-too-strict on an input side. |
Does it help if I just make a PR to revert it? In the future I'm happy to review changes like these if that helps. |
@longlho Why is it ok for formatjs to use an enum there, but not TS? 🤔 |
because that's the set of stuff we specifically support :) so if you're using formatjs you only get access to those calendar/numbering systems. If you use a browser's non-polyfilled Intl then it's unknown. |
Right, so an alternative fix would be for formatjs to do this: -export interface DateTimeFormatOptions extends Intl.DateTimeFormatOptions {
+export interface DateTimeFormatOptions extends Omit<Intl.DateTimeFormatOptions, 'calendar'> { |
Those are 2 separate problems though. I'm saying TS provides low level type def for ECMA402 API and right now it's in unspec'ed land with |
Fixes #42128