fix: add Intl.getCanonicalLocales
type definition
#56079
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 ates2020.intl.d.ts
. In the past, A comment of #39662 has tried to supportUnicodeBCP47LocaleIdentifier
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 forstring
. So, as a compromise, the parameters and return value ofIntl.getCanonicalLocales
are defined as string. by that way, we can keep compatibility.