Skip to content

Commit 689bf6f

Browse files
committed
Allow undefined in Intl inputs to allow for ergonomic usage of exactOptionalPropertyTypes - see microsoft#45652
1 parent 5f67f65 commit 689bf6f

File tree

5 files changed

+64
-58
lines changed

5 files changed

+64
-58
lines changed

src/lib/es2018.intl.d.ts

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ declare namespace Intl {
55
type PluralRuleType = "cardinal" | "ordinal";
66

77
interface PluralRulesOptions {
8-
localeMatcher?: "lookup" | "best fit";
9-
type?: PluralRuleType;
10-
minimumIntegerDigits?: number;
11-
minimumFractionDigits?: number;
12-
maximumFractionDigits?: number;
13-
minimumSignificantDigits?: number;
14-
maximumSignificantDigits?: number;
8+
localeMatcher?: "lookup" | "best fit" | undefined;
9+
type?: PluralRuleType | undefined;
10+
minimumIntegerDigits?: number | undefined;
11+
minimumFractionDigits?: number | undefined;
12+
maximumFractionDigits?: number | undefined;
13+
minimumSignificantDigits?: number | undefined;
14+
maximumSignificantDigits?: number | undefined;
1515
}
1616

1717
interface ResolvedPluralRulesOptions {
@@ -33,10 +33,8 @@ declare namespace Intl {
3333
const PluralRules: {
3434
new (locales?: string | string[], options?: PluralRulesOptions): PluralRules;
3535
(locales?: string | string[], options?: PluralRulesOptions): PluralRules;
36-
supportedLocalesOf(
37-
locales: string | string[],
38-
options?: PluralRulesOptions,
39-
): string[];
36+
37+
supportedLocalesOf(locales: string | string[], options?: { localeMatcher?: "lookup" | "best fit" }): string[];
4038
};
4139

4240
interface NumberFormatPart {

src/lib/es2020.intl.d.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -198,11 +198,11 @@ declare namespace Intl {
198198
};
199199

200200
interface NumberFormatOptions {
201-
compactDisplay?: "short" | "long";
202-
notation?: "standard" | "scientific" | "engineering" | "compact";
203-
signDisplay?: "auto" | "never" | "always";
204-
unit?: NumberFormatUnit;
205-
unitDisplay?: "short" | "long" | "narrow";
201+
compactDisplay?: "short" | "long" | undefined;
202+
notation?: "standard" | "scientific" | "engineering" | "compact" | undefined;
203+
signDisplay?: "auto" | "never" | "always" | undefined;
204+
unit?: NumberFormatUnit | undefined;
205+
unitDisplay?: "short" | "long" | "narrow" | undefined;
206206
}
207207

208208
interface ResolvedNumberFormatOptions {
@@ -214,16 +214,16 @@ declare namespace Intl {
214214
}
215215

216216
interface DateTimeFormatOptions {
217-
calendar?: string;
218-
dayPeriod?: "narrow" | "short" | "long";
219-
numberingSystem?: string;
220-
hourCycle?: "h11" | "h12" | "h23" | "h24";
217+
calendar?: string | undefined;
218+
dayPeriod?: "narrow" | "short" | "long" | undefined;
219+
numberingSystem?: string | undefined;
220+
hourCycle?: "h11" | "h12" | "h23" | "h24" | undefined;
221221
}
222222

223223
interface DateTimeFormatOptions {
224-
dateStyle?: "full" | "long" | "medium" | "short";
225-
timeStyle?: "full" | "long" | "medium" | "short";
226-
hourCycle?: "h11" | "h12" | "h23" | "h24";
224+
dateStyle?: "full" | "long" | "medium" | "short" | undefined;
225+
timeStyle?: "full" | "long" | "medium" | "short" | undefined;
226+
hourCycle?: "h11" | "h12" | "h23" | "h24" | undefined;
227227
}
228228

229229
type LocaleHourCycleKey = "h12" | "h23" | "h11" | "h24";
@@ -345,7 +345,7 @@ declare namespace Intl {
345345
*
346346
* [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/supportedLocalesOf).
347347
*/
348-
supportedLocalesOf(locales: BCP47LanguageTag | BCP47LanguageTag[], options: {localeMatcher: RelativeTimeFormatLocaleMatcher}): BCP47LanguageTag[];
348+
supportedLocalesOf(locales: BCP47LanguageTag | BCP47LanguageTag[], options?: {localeMatcher: RelativeTimeFormatLocaleMatcher}): BCP47LanguageTag[];
349349
};
350350

351351
}

src/lib/es2021.intl.d.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
declare namespace Intl {
22

33
interface DateTimeFormatOptions {
4-
dateStyle?: "full" | "long" | "medium" | "short";
5-
timeStyle?: "full" | "long" | "medium" | "short";
6-
dayPeriod?: "narrow" | "short" | "long";
7-
fractionalSecondDigits?: 0 | 1 | 2 | 3;
4+
dateStyle?: "full" | "long" | "medium" | "short" | undefined;
5+
timeStyle?: "full" | "long" | "medium" | "short" | undefined;
6+
dayPeriod?: "narrow" | "short" | "long" | undefined;
7+
fractionalSecondDigits?: 0 | 1 | 2 | 3 | undefined;
88
}
99
}

src/lib/es5.d.ts

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4295,12 +4295,12 @@ declare var Float64Array: Float64ArrayConstructor;
42954295

42964296
declare namespace Intl {
42974297
interface CollatorOptions {
4298-
usage?: string;
4299-
localeMatcher?: string;
4300-
numeric?: boolean;
4301-
caseFirst?: string;
4302-
sensitivity?: string;
4303-
ignorePunctuation?: boolean;
4298+
usage?: string | undefined;
4299+
localeMatcher?: string | undefined;
4300+
numeric?: boolean | undefined;
4301+
caseFirst?: string | undefined;
4302+
sensitivity?: string | undefined;
4303+
ignorePunctuation?: boolean | undefined;
43044304
}
43054305

43064306
interface ResolvedCollatorOptions {
@@ -4324,17 +4324,17 @@ declare namespace Intl {
43244324
};
43254325

43264326
interface NumberFormatOptions {
4327-
localeMatcher?: string;
4328-
style?: string;
4329-
currency?: string;
4330-
currencyDisplay?: string;
4331-
currencySign?: string;
4332-
useGrouping?: boolean;
4333-
minimumIntegerDigits?: number;
4334-
minimumFractionDigits?: number;
4335-
maximumFractionDigits?: number;
4336-
minimumSignificantDigits?: number;
4337-
maximumSignificantDigits?: number;
4327+
localeMatcher?: string | undefined;
4328+
style?: string | undefined;
4329+
currency?: string | undefined;
4330+
currencyDisplay?: string | undefined;
4331+
currencySign?: string | undefined;
4332+
useGrouping?: boolean | undefined;
4333+
minimumIntegerDigits?: number | undefined;
4334+
minimumFractionDigits?: number | undefined;
4335+
maximumFractionDigits?: number | undefined;
4336+
minimumSignificantDigits?: number | undefined;
4337+
maximumSignificantDigits?: number | undefined;
43384338
}
43394339

43404340
interface ResolvedNumberFormatOptions {
@@ -4362,19 +4362,19 @@ declare namespace Intl {
43624362
};
43634363

43644364
interface DateTimeFormatOptions {
4365-
localeMatcher?: "best fit" | "lookup";
4366-
weekday?: "long" | "short" | "narrow";
4367-
era?: "long" | "short" | "narrow";
4368-
year?: "numeric" | "2-digit";
4369-
month?: "numeric" | "2-digit" | "long" | "short" | "narrow";
4370-
day?: "numeric" | "2-digit";
4371-
hour?: "numeric" | "2-digit";
4372-
minute?: "numeric" | "2-digit";
4373-
second?: "numeric" | "2-digit";
4374-
timeZoneName?: "long" | "short";
4375-
formatMatcher?: "best fit" | "basic";
4376-
hour12?: boolean;
4377-
timeZone?: string;
4365+
localeMatcher?: "best fit" | "lookup" | undefined;
4366+
weekday?: "long" | "short" | "narrow" | undefined;
4367+
era?: "long" | "short" | "narrow" | undefined;
4368+
year?: "numeric" | "2-digit" | undefined;
4369+
month?: "numeric" | "2-digit" | "long" | "short" | "narrow" | undefined;
4370+
day?: "numeric" | "2-digit" | undefined;
4371+
hour?: "numeric" | "2-digit" | undefined;
4372+
minute?: "numeric" | "2-digit" | undefined;
4373+
second?: "numeric" | "2-digit" | undefined;
4374+
timeZoneName?: "long" | "short" | undefined;
4375+
formatMatcher?: "best fit" | "basic" | undefined;
4376+
hour12?: boolean | undefined;
4377+
timeZone?: string | undefined;
43784378
}
43794379

43804380
interface ResolvedDateTimeFormatOptions {
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// @target: es5
2+
// @lib: es6,es2018
3+
4+
// Sample from
5+
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/PluralRules/supportedLocalesOf
6+
const locales = ['ban', 'id-u-co-pinyin', 'de-ID'];
7+
const options = { localeMatcher: 'lookup' } as const;
8+
console.log(Intl.PluralRules.supportedLocalesOf(locales, options).join(', '));

0 commit comments

Comments
 (0)