-
Notifications
You must be signed in to change notification settings - Fork 28
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
TypeScript: allow Intl.Locale objects in locale list params #224
base: main
Are you sure you want to change the base?
Conversation
e9f8cdb
to
0214e5e
Compare
As far as I can tell, this symbol is relatively new? https://stackoverflow.com/questions/73637484/namespace-intl-has-no-exported-member-localesargument Presumably, if we add this then our .d.ts file will be incompatible with downstream ts users who don't have a relatively up to date TS. This is typically solved using |
@12wrigja We've solved this for other built-in types by duplicating the types in our own .d.ts. Add long as the types match exactly, this won't break TSC in later versions of TS. Seems simple to do the same thing here. What do you think? |
Duplicating is basically what the fallback for typesVersions would do. I'm just suggesting having multiple versions so that we automatically stay up to date as the upstream Intl typings change. |
And realistically wouldn't the typings that end up in the standard .d.ts for TS itself use the Intl symbols instead of a duplicate? |
Given that TS will do declaration merging, what's the advantage of having separate per-TS-version type declaration files that would outweigh the complexity of maintaining separate files? For example, Lines 1526 to 1533 in c0f7349
Yep, but as long as the parts of our types match what's in TS's own |
c5b14cd
to
6e689dc
Compare
I've duplicated |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR. LGTM! @12wrigja feel free to merge if you think this change is OK.
I'd like to verify this works when compiling against TS versions that don't define LocalesArgument before merging. |
Ultimately, the PR in it's current state works (as the .d.ts doesn't explicitly reference
Thoughts @justingrant? @lionel-rowe I'd be more than happy for you to copy my WIP PR above and fix it up if you'd still like to contribute this fix. |
Thanks @12wrigja — I've updated PR with that fix. I've set the threshold at <4.7.4, as 4.7.4 has the type but 4.6.4 is missing it. |
I'm happy with this, but would like @justingrant to take a look too. |
6516a2e
to
c6554c5
Compare
After reading over https://twitter.com/atcb/status/1634653474041503744?s=46&t=QSggAfTZ89VDmJRcZoeQ0A, I think we might need some small adjustments to the build so that this works consistently (as typesVersions is only used when exports is not).
Based on microsoft/TypeScript#50890 (comment). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Should we also consider a similar trick for our existing re-declaration below?
// TODO: remove the props below after TS lib declarations are updated
dayPeriod?: 'narrow' | 'short' | 'long';
dateStyle?: 'full' | 'long' | 'medium' | 'short';
timeStyle?: 'full' | 'long' | 'medium' | 'short';
Just ran into this, as I encountered this typing issue myself when trying to pass some |
This PR allows
locales
parameters to acceptIntl.Locale
objects (or arrays thereof). This already works fine in plain JS, but the current TS types are overly restrictive.See also: microsoft/TypeScript#52946
Note that
Intl.DateTimeFormat
already acceptsIntl.Locale
s — the casting toas ConstructorParameters<typeof IntlDateTimeFormat>[0]
is only needed until the TSlib
issue is fixed.