Consistently allow Locale objects in locale list params (#52996)

This commit is contained in:
lionel-rowe
2023-11-29 17:21:49 +00:00
committed by GitHub
parent aef29e400e
commit f97c3fd377
31 changed files with 936 additions and 81 deletions

View File

@@ -29,12 +29,13 @@ declare namespace Intl {
select(n: number): LDMLPluralRule;
}
const PluralRules: {
interface PluralRulesConstructor {
new (locales?: string | string[], options?: PluralRulesOptions): PluralRules;
(locales?: string | string[], options?: PluralRulesOptions): PluralRules;
supportedLocalesOf(locales: string | string[], options?: { localeMatcher?: "lookup" | "best fit"; }): string[];
};
}
const PluralRules: PluralRulesConstructor;
// We can only have one definition for 'type' in TypeScript, and so you can learn where the keys come from here:
type ES2018NumberFormatPartType = "literal" | "nan" | "infinity" | "percent" | "integer" | "group" | "decimal" | "fraction" | "plusSign" | "minusSign" | "percentSign" | "currency" | "code" | "symbol" | "name";

View File

@@ -1,9 +1,11 @@
/// <reference lib="es2018.intl" />
declare namespace Intl {
/**
* [Unicode BCP 47 Locale Identifiers](https://unicode.org/reports/tr35/#Unicode_Language_and_Locale_Identifiers) definition.
* A string that is a valid [Unicode BCP 47 Locale Identifier](https://unicode.org/reports/tr35/#Unicode_locale_identifier).
*
* [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl#locales_argument).
* For example: "fa", "es-MX", "zh-Hant-TW".
*
* See [MDN - Intl - locales argument](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl#locales_argument).
*/
type UnicodeBCP47LocaleIdentifier = string;
@@ -71,16 +73,9 @@ declare namespace Intl {
type RelativeTimeFormatStyle = "long" | "short" | "narrow";
/**
* [BCP 47 language tag](http://tools.ietf.org/html/rfc5646) definition.
* The locale or locales to use
*
* [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl#locales_argument).
*/
type BCP47LanguageTag = string;
/**
* The locale(s) to use
*
* [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl#locales_argument).
* See [MDN - Intl - locales argument](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl#locales_argument).
*/
type LocalesArgument = UnicodeBCP47LocaleIdentifier | Locale | readonly (UnicodeBCP47LocaleIdentifier | Locale)[] | undefined;
@@ -200,7 +195,7 @@ declare namespace Intl {
* [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/RelativeTimeFormat).
*/
new (
locales?: UnicodeBCP47LocaleIdentifier | UnicodeBCP47LocaleIdentifier[],
locales?: LocalesArgument,
options?: RelativeTimeFormatOptions,
): RelativeTimeFormat;
@@ -223,7 +218,7 @@ declare namespace Intl {
* [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/supportedLocalesOf).
*/
supportedLocalesOf(
locales?: UnicodeBCP47LocaleIdentifier | UnicodeBCP47LocaleIdentifier[],
locales?: LocalesArgument,
options?: RelativeTimeFormatOptions,
): UnicodeBCP47LocaleIdentifier[];
};
@@ -294,7 +289,7 @@ declare namespace Intl {
/** Attempts to remove information about the locale that would be added by calling `Locale.maximize()`. */
minimize(): Locale;
/** Returns the locale's full locale identifier string. */
toString(): BCP47LanguageTag;
toString(): UnicodeBCP47LocaleIdentifier;
}
/**
@@ -312,7 +307,7 @@ declare namespace Intl {
* [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale).
*/
const Locale: {
new (tag: BCP47LanguageTag | Locale, options?: LocaleOptions): Locale;
new (tag: UnicodeBCP47LocaleIdentifier | Locale, options?: LocaleOptions): Locale;
};
type DisplayNamesFallback =
@@ -406,6 +401,31 @@ declare namespace Intl {
*
* [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/supportedLocalesOf).
*/
supportedLocalesOf(locales?: LocalesArgument, options?: { localeMatcher?: RelativeTimeFormatLocaleMatcher; }): BCP47LanguageTag[];
supportedLocalesOf(locales?: LocalesArgument, options?: { localeMatcher?: RelativeTimeFormatLocaleMatcher; }): UnicodeBCP47LocaleIdentifier[];
};
interface CollatorConstructor {
new (locales?: LocalesArgument, options?: CollatorOptions): Collator;
(locales?: LocalesArgument, options?: CollatorOptions): Collator;
supportedLocalesOf(locales: LocalesArgument, options?: CollatorOptions): string[];
}
interface DateTimeFormatConstructor {
new (locales?: LocalesArgument, options?: DateTimeFormatOptions): DateTimeFormat;
(locales?: LocalesArgument, options?: DateTimeFormatOptions): DateTimeFormat;
supportedLocalesOf(locales: LocalesArgument, options?: DateTimeFormatOptions): string[];
}
interface NumberFormatConstructor {
new (locales?: LocalesArgument, options?: NumberFormatOptions): NumberFormat;
(locales?: LocalesArgument, options?: NumberFormatOptions): NumberFormat;
supportedLocalesOf(locales: LocalesArgument, options?: NumberFormatOptions): string[];
}
interface PluralRulesConstructor {
new (locales?: LocalesArgument, options?: PluralRulesOptions): PluralRules;
(locales?: LocalesArgument, options?: PluralRulesOptions): PluralRules;
supportedLocalesOf(locales: LocalesArgument, options?: { localeMatcher?: "lookup" | "best fit"; }): string[];
}
}

View File

@@ -7,4 +7,18 @@ interface String {
* @param regexp A variable name or string literal containing the regular expression pattern and flags.
*/
matchAll(regexp: RegExp): IterableIterator<RegExpMatchArray>;
/** Converts all alphabetic characters to lowercase, taking into account the host environment's current locale. */
toLocaleLowerCase(locales?: Intl.LocalesArgument): string;
/** Returns a string where all alphabetic characters have been converted to uppercase, taking into account the host environment's current locale. */
toLocaleUpperCase(locales?: Intl.LocalesArgument): string;
/**
* Determines whether two strings are equivalent in the current or specified locale.
* @param that String to compare to target string
* @param locales A locale string or array of locale strings that contain one or more language or locale tags. If you include more than one locale string, list them in descending order of priority so that the first entry is the preferred locale. If you omit this parameter, the default locale of the JavaScript runtime is used. This parameter must conform to BCP 47 standards; see the Intl.Collator object for details.
* @param options An object that contains one or more properties that specify comparison options. see the Intl.Collator object for details.
*/
localeCompare(that: string, locales?: Intl.LocalesArgument, options?: Intl.CollatorOptions): number;
}

View File

@@ -125,7 +125,7 @@ declare namespace Intl {
*
* [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat).
*/
new (locales?: BCP47LanguageTag | BCP47LanguageTag[], options?: ListFormatOptions): ListFormat;
new (locales?: LocalesArgument, options?: ListFormatOptions): ListFormat;
/**
* Returns an array containing those of the provided locales that are
@@ -143,6 +143,6 @@ declare namespace Intl {
*
* [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/supportedLocalesOf).
*/
supportedLocalesOf(locales: BCP47LanguageTag | BCP47LanguageTag[], options?: Pick<ListFormatOptions, "localeMatcher">): BCP47LanguageTag[];
supportedLocalesOf(locales: LocalesArgument, options?: Pick<ListFormatOptions, "localeMatcher">): UnicodeBCP47LocaleIdentifier[];
};
}

View File

@@ -71,7 +71,7 @@ declare namespace Intl {
*
* [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter).
*/
new (locales?: BCP47LanguageTag | BCP47LanguageTag[], options?: SegmenterOptions): Segmenter;
new (locales?: LocalesArgument, options?: SegmenterOptions): Segmenter;
/**
* Returns an array containing those of the provided locales that are supported without having to fall back to the runtime's default locale.
@@ -85,7 +85,7 @@ declare namespace Intl {
*
* [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter/supportedLocalesOf)
*/
supportedLocalesOf(locales: BCP47LanguageTag | BCP47LanguageTag[], options?: Pick<SegmenterOptions, "localeMatcher">): BCP47LanguageTag[];
supportedLocalesOf(locales: LocalesArgument, options?: Pick<SegmenterOptions, "localeMatcher">): UnicodeBCP47LocaleIdentifier[];
};
/**

21
src/lib/es5.d.ts vendored
View File

@@ -4400,11 +4400,14 @@ declare namespace Intl {
compare(x: string, y: string): number;
resolvedOptions(): ResolvedCollatorOptions;
}
var Collator: {
interface CollatorConstructor {
new (locales?: string | string[], options?: CollatorOptions): Collator;
(locales?: string | string[], options?: CollatorOptions): Collator;
supportedLocalesOf(locales: string | string[], options?: CollatorOptions): string[];
};
}
var Collator: CollatorConstructor;
interface NumberFormatOptions {
localeMatcher?: string | undefined;
@@ -4436,12 +4439,15 @@ declare namespace Intl {
format(value: number): string;
resolvedOptions(): ResolvedNumberFormatOptions;
}
var NumberFormat: {
interface NumberFormatConstructor {
new (locales?: string | string[], options?: NumberFormatOptions): NumberFormat;
(locales?: string | string[], options?: NumberFormatOptions): NumberFormat;
supportedLocalesOf(locales: string | string[], options?: NumberFormatOptions): string[];
readonly prototype: NumberFormat;
};
}
var NumberFormat: NumberFormatConstructor;
interface DateTimeFormatOptions {
localeMatcher?: "best fit" | "lookup" | undefined;
@@ -4480,12 +4486,15 @@ declare namespace Intl {
format(date?: Date | number): string;
resolvedOptions(): ResolvedDateTimeFormatOptions;
}
var DateTimeFormat: {
interface DateTimeFormatConstructor {
new (locales?: string | string[], options?: DateTimeFormatOptions): DateTimeFormat;
(locales?: string | string[], options?: DateTimeFormatOptions): DateTimeFormat;
supportedLocalesOf(locales: string | string[], options?: DateTimeFormatOptions): string[];
readonly prototype: DateTimeFormat;
};
}
var DateTimeFormat: DateTimeFormatConstructor;
}
interface String {