Skip to content

Commit 07fd7bc

Browse files
Orta Theroxsandersn
Orta Therox
andauthored
Intl 2021 Updates (#45647)
* Import of Intl.Locale from #39664 * Handle updating es2020.intl and add es2021 for new DateTimeFormatOptions options - re: #39664 * Extends DateTimeFormatOptions for new Intl APIs - re: #45420 * Handle migrating Intl.NumberFormat.formatToParts to es2018 (keeping esnext.intl around) * Adds Intl.DisplayNames to es2020 - re: #44022 * Remove attributes added in es2021 from es2020 - re: #42944 * Add a reference to es2021 in the command line parser * Adds some docs about the lib files * Baselines * Allow undefined in Intl inputs to allow for ergonomic usage of exactOptionalPropertyTypes - see #45652 * Adds some tests covering the APIs * Apply suggestions from code review Co-authored-by: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> * Handle PR feedback * More review improvements Co-authored-by: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com>
1 parent 32168ed commit 07fd7bc

27 files changed

+891
-234
lines changed

lib/lib.es2021.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,4 @@ and limitations under the License.
2222
/// <reference lib="es2021.promise" />
2323
/// <reference lib="es2021.string" />
2424
/// <reference lib="es2021.weakref" />
25+
/// <reference lib="es2021.intl" />

src/compiler/commandLineParser.ts

+1
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ namespace ts {
7171
["es2021.promise", "lib.es2021.promise.d.ts"],
7272
["es2021.string", "lib.es2021.string.d.ts"],
7373
["es2021.weakref", "lib.es2021.weakref.d.ts"],
74+
["es2021.intl", "lib.es2021.intl.d.ts"],
7475
["esnext.array", "lib.es2019.array.d.ts"],
7576
["esnext.symbol", "lib.es2019.symbol.d.ts"],
7677
["esnext.asynciterable", "lib.es2018.asynciterable.d.ts"],

src/lib/README.md

+21-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,26 @@
11
# Read this!
22

3-
The files within this directory are used to generate `lib.d.ts` and `lib.es6.d.ts`.
3+
The files within this directory are copied and deployed with TypeScript as the set of APIs available as a part of the JavaScript language.
4+
5+
There are three main domains of APIs in `src/lib`:
6+
7+
- **ECMAScript language features** - e.g. JavaScript APIs like functions on Array etc which are documented in [ECMA-262](https://tc39.es/ecma262/)
8+
- **DOM APIs** - e.g. APIs which are available in web browsers
9+
- **Intl APIs** - e.g. APIs scoped to `Intl` which are documented in [ECMA-402](https://www.ecma-international.org/publications-and-standards/standards/ecma-402/)
10+
11+
## How do we figure out when to add something?
12+
13+
TypeScript has a rule-of-thumb to only add something when it has got far enough through the standards process that it is more or less confirmed. For JavaScript APIs and language features, that means the proposal is at stage 3 or later.
14+
15+
You can find the source of truth for modern language features and Intl APIs in these completed proposal lists:
16+
17+
- [JavaScript](https://github.com/tc39/proposals/blob/master/finished-proposals.md)
18+
- [Intl](https://github.com/tc39/proposals/blob/master/ecma402/finished-proposals.md)
19+
20+
For the DOM APIs, which are a bit more free-form, we have asked that APIs are available un-prefixed/flagged in at least 2 browser _engines_ (i.e. not just 2 chromium browsers.)
421

522
## Generated files
623

7-
Any files ending in `.generated.d.ts` aren't meant to be edited by hand.
8-
If you need to make changes to such files, make a change to the input files for [**our library generator**](https://github.com/Microsoft/TSJS-lib-generator).
24+
The DOM files ending in `.generated.d.ts` aren't meant to be edited by hand.
25+
26+
If you need to make changes to such files, make a change to the input files for [**our library generator**](https://github.com/microsoft/TypeScript-DOM-lib-generator).

src/lib/es2018.intl.d.ts

+19-11
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,9 +33,17 @@ 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
};
39+
40+
type ES2018NumberFormatPartType = "literal" | "nan" | "infinity" | "percent" | "integer" | "group" | "decimal" | "fraction" | "plusSign" | "minusSign" | "percentSign" | "currency" | "code" | "symbol" | "name";
41+
interface NumberFormatPart {
42+
type: ES2018NumberFormatPartType;
43+
value: string;
44+
}
45+
46+
interface NumberFormat {
47+
formatToParts(number?: number | bigint): NumberFormatPart[];
48+
}
4149
}

src/lib/es2020.intl.d.ts

+179-115
Large diffs are not rendered by default.

src/lib/es2021.intl.d.ts

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
declare namespace Intl {
2+
3+
interface DateTimeFormatOptions {
4+
formatMatcher?: "basic" | "best fit" | "best fit" | undefined;
5+
dateStyle?: "full" | "long" | "medium" | "short" | undefined;
6+
timeStyle?: "full" | "long" | "medium" | "short" | undefined;
7+
dayPeriod?: "narrow" | "short" | "long" | undefined;
8+
fractionalSecondDigits?: 0 | 1 | 2 | 3 | undefined;
9+
}
10+
11+
interface NumberFormat {
12+
formatRange(startDate: number | bigint, endDate: number | bigint): string;
13+
formatRangeToParts(startDate: number | bigint, endDate: number | bigint): NumberFormatPart[];
14+
}
15+
}

src/lib/es5.d.ts

+30-30
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 {

src/lib/esnext.intl.d.ts

+1-10
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,3 @@
11
declare namespace Intl {
2-
type NumberFormatPartTypes = "compact" | "currency" | "decimal" | "exponentInteger" | "exponentMinusSign" | "exponentSeparator" | "fraction" | "group" | "infinity" | "integer" | "literal" | "minusSign" | "nan" | "plusSign" | "percentSign" | "unit" | "unknown";
3-
4-
interface NumberFormatPart {
5-
type: NumberFormatPartTypes;
6-
value: string;
7-
}
8-
9-
interface NumberFormat {
10-
formatToParts(number?: number | bigint): NumberFormatPart[];
11-
}
2+
// Empty for now
123
}

src/lib/libs.json

+1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
"es2021.string",
5252
"es2021.promise",
5353
"es2021.weakref",
54+
"es2021.intl",
5455
"esnext.intl",
5556
// Default libraries
5657
"es5.full",

tests/baselines/reference/bigintWithLib.symbols

+4-4
Original file line numberDiff line numberDiff line change
@@ -241,16 +241,16 @@ let z = 12n; // should emit type bigint in declaration file
241241
// Test Intl methods with new parameter type
242242
new Intl.NumberFormat("fr").format(3000n);
243243
>new Intl.NumberFormat("fr").format : Symbol(Intl.NumberFormat.format, Decl(lib.es5.d.ts, --, --), Decl(lib.es2020.bigint.d.ts, --, --))
244-
>Intl.NumberFormat : Symbol(Intl.NumberFormat, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2020.bigint.d.ts, --, --))
244+
>Intl.NumberFormat : Symbol(Intl.NumberFormat, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2018.intl.d.ts, --, --), Decl(lib.es2020.bigint.d.ts, --, --))
245245
>Intl : Symbol(Intl, Decl(lib.es5.d.ts, --, --), Decl(lib.es2017.intl.d.ts, --, --), Decl(lib.es2018.intl.d.ts, --, --), Decl(lib.es2020.bigint.d.ts, --, --), Decl(lib.es2020.intl.d.ts, --, --))
246-
>NumberFormat : Symbol(Intl.NumberFormat, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2020.bigint.d.ts, --, --))
246+
>NumberFormat : Symbol(Intl.NumberFormat, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2018.intl.d.ts, --, --), Decl(lib.es2020.bigint.d.ts, --, --))
247247
>format : Symbol(Intl.NumberFormat.format, Decl(lib.es5.d.ts, --, --), Decl(lib.es2020.bigint.d.ts, --, --))
248248

249249
new Intl.NumberFormat("fr").format(bigintVal);
250250
>new Intl.NumberFormat("fr").format : Symbol(Intl.NumberFormat.format, Decl(lib.es5.d.ts, --, --), Decl(lib.es2020.bigint.d.ts, --, --))
251-
>Intl.NumberFormat : Symbol(Intl.NumberFormat, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2020.bigint.d.ts, --, --))
251+
>Intl.NumberFormat : Symbol(Intl.NumberFormat, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2018.intl.d.ts, --, --), Decl(lib.es2020.bigint.d.ts, --, --))
252252
>Intl : Symbol(Intl, Decl(lib.es5.d.ts, --, --), Decl(lib.es2017.intl.d.ts, --, --), Decl(lib.es2018.intl.d.ts, --, --), Decl(lib.es2020.bigint.d.ts, --, --), Decl(lib.es2020.intl.d.ts, --, --))
253-
>NumberFormat : Symbol(Intl.NumberFormat, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2020.bigint.d.ts, --, --))
253+
>NumberFormat : Symbol(Intl.NumberFormat, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2018.intl.d.ts, --, --), Decl(lib.es2020.bigint.d.ts, --, --))
254254
>format : Symbol(Intl.NumberFormat.format, Decl(lib.es5.d.ts, --, --), Decl(lib.es2020.bigint.d.ts, --, --))
255255
>bigintVal : Symbol(bigintVal, Decl(bigintWithLib.ts, 1, 3))
256256

0 commit comments

Comments
 (0)