Skip to content
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

fix: add Intl.getCanonicalLocales type definition #56079

Merged
merged 7 commits into from
Nov 3, 2023

Conversation

kazupon
Copy link
Contributor

@kazupon kazupon commented Oct 12, 2023

Fixes #29129

The issue to resolve this PR is not Backlog milestone.
Intl.getCanonicalLocales type definition should be included in #45647, but unfortunately it could not do.

Even now, the Intl.getCanonicalLocales type is not resolved.
We can check it in the playground.
https://www.typescriptlang.org/play?ssl=1&ssc=6&pln=1&pc=25#code/JIOwLgNgdA5gpmAwgQxAexASwMbIgGTVwjgGcg

about Intl.getCanonicalLocales

why do i add as es2016.intl

Intl.getCanonicalLocales is supported since 2016, so some proejcts using typescript might still use es2016.
I've added es2016.intl.d.ts for compatibility and defined in it.

Parameters and return types of Intl.getCanonicalLocales

UnicodeBCP47LocaleIdentifier is not defined at es2020.intl.d.ts. In the past, A comment of #39662 has tried to support UnicodeBCP47LocaleIdentifier by defining it in es2016.
However, if we do that, it will result in a destructive change for some users, as this comment states.

UnicodeBCP47LocaleIdentifier is currently an alias for string. So, as a compromise, the parameters and return value of Intl.getCanonicalLocales are defined as string. by that way, we can keep compatibility.

@typescript-bot typescript-bot added the For Uncommitted Bug PR for untriaged, rejected, closed or missing bug label Oct 12, 2023
@typescript-bot
Copy link
Collaborator

The TypeScript team hasn't accepted the linked issue #29129. If you can get it accepted, this PR will have a better chance of being reviewed.

@kazupon
Copy link
Contributor Author

kazupon commented Oct 12, 2023

@microsoft-github-policy-service agree

@sandersn sandersn self-assigned this Nov 3, 2023
@sandersn
Copy link
Member

sandersn commented Nov 3, 2023

It took a lot of digging, but I found proof that this was indeed added in 2016: The first page of https://402.ecma-international.org/3.0/ mentions it explicitly.

@sandersn sandersn merged commit 09fc67b into microsoft:main Nov 3, 2023
19 checks passed
@kazupon kazupon deleted the fix/intl-get-canonicalLocales branch November 4, 2023 11:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
For Uncommitted Bug PR for untriaged, rejected, closed or missing bug
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

[i18n] Intl getCanonicalLocales / RelativeTimeFormat / ListFormat > 2339 error
3 participants