Skip to content

Commit 312737b

Browse files
feat(46907): Add Intl.ListFormat type declarations (#47254)
* feat(46907): Add ListFormat type declarations * feat(46907): Fix JSDoc return type * feat(46907): Use correct formatToParts list parameter type description, link to Array MDN page * refactor(46907): Change ListFormatLocaleMatcher MDN link to match the rest * feat(46907): Add explicit undefined to ListFormatOptions
1 parent c99afde commit 312737b

File tree

1 file changed

+102
-0
lines changed

1 file changed

+102
-0
lines changed

src/lib/es2021.intl.d.ts

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,106 @@ declare namespace Intl {
2121
dayPeriod?: "narrow" | "short" | "long";
2222
fractionalSecondDigits?: 0 | 1 | 2 | 3;
2323
}
24+
25+
/**
26+
* The locale matching algorithm to use.
27+
*
28+
* [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/ListFormat#parameters).
29+
*/
30+
type ListFormatLocaleMatcher = "lookup" | "best fit";
31+
32+
/**
33+
* The format of output message.
34+
*
35+
* [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/ListFormat#parameters).
36+
*/
37+
type ListFormatType = "conjunction" | "disjunction" | "unit";
38+
39+
/**
40+
* The length of the formatted message.
41+
*
42+
* [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/ListFormat#parameters).
43+
*/
44+
type ListFormatStyle = "long" | "short" | "narrow";
45+
46+
/**
47+
* An object with some or all properties of the `Intl.ListFormat` constructor `options` parameter.
48+
*
49+
* [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/ListFormat#parameters).
50+
*/
51+
interface ListFormatOptions {
52+
/** The locale matching algorithm to use. For information about this option, see [Intl page](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Intl#Locale_negotiation). */
53+
localeMatcher?: ListFormatLocaleMatcher | undefined;
54+
/** The format of output message. */
55+
type?: ListFormatType | undefined;
56+
/** The length of the internationalized message. */
57+
style?: ListFormatStyle | undefined;
58+
}
59+
60+
interface ListFormat {
61+
/**
62+
* Returns a string with a language-specific representation of the list.
63+
*
64+
* @param list - An iterable object, such as an [Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array).
65+
*
66+
* @throws `TypeError` if `list` includes something other than the possible values.
67+
*
68+
* @returns {string} A language-specific formatted string representing the elements of the list.
69+
*
70+
* [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/format).
71+
*/
72+
format(list: Iterable<string>): string;
73+
74+
/**
75+
* Returns an Array of objects representing the different components that can be used to format a list of values in a locale-aware fashion.
76+
*
77+
* @param list - An iterable object, such as an [Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array), to be formatted according to a locale.
78+
*
79+
* @throws `TypeError` if `list` includes something other than the possible values.
80+
*
81+
* @returns {{ type: "element" | "literal", value: string; }[]} An Array of components which contains the formatted parts from the list.
82+
*
83+
* [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/formatToParts).
84+
*/
85+
formatToParts(list: Iterable<string>): { type: "element" | "literal", value: string; }[];
86+
}
87+
88+
const ListFormat: {
89+
prototype: ListFormat;
90+
91+
/**
92+
* Creates [Intl.ListFormat](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat) objects that
93+
* enable language-sensitive list formatting.
94+
*
95+
* @param locales - A string with a [BCP 47 language tag](http://tools.ietf.org/html/rfc5646), or an array of such strings.
96+
* For the general form and interpretation of the `locales` argument,
97+
* see the [`Intl` page](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl#Locale_identification_and_negotiation).
98+
*
99+
* @param options - An [object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/ListFormat#parameters)
100+
* with some or all options of `ListFormatOptions`.
101+
*
102+
* @returns [Intl.ListFormatOptions](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat) object.
103+
*
104+
* [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat).
105+
*/
106+
new(locales?: BCP47LanguageTag | BCP47LanguageTag[], options?: ListFormatOptions): ListFormat;
107+
108+
/**
109+
* Returns an array containing those of the provided locales that are
110+
* supported in list formatting without having to fall back to the runtime's default locale.
111+
*
112+
* @param locales - A string with a [BCP 47 language tag](http://tools.ietf.org/html/rfc5646), or an array of such strings.
113+
* For the general form and interpretation of the `locales` argument,
114+
* see the [`Intl` page](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl#Locale_identification_and_negotiation).
115+
*
116+
* @param options - An [object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/supportedLocalesOf#parameters).
117+
* with some or all possible options.
118+
*
119+
* @returns An array of strings representing a subset of the given locale tags that are supported in list
120+
* formatting without having to fall back to the runtime's default locale.
121+
*
122+
* [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/supportedLocalesOf).
123+
*/
124+
supportedLocalesOf(locales: BCP47LanguageTag | BCP47LanguageTag[], options?: Pick<ListFormatOptions, "localeMatcher">): BCP47LanguageTag[];
125+
};
24126
}

0 commit comments

Comments
 (0)