From ad15e541b0972f17572ada589b621c276580770e Mon Sep 17 00:00:00 2001 From: Orta Date: Mon, 30 Aug 2021 21:42:16 +0100 Subject: [PATCH 01/14] Import of Intl.Locale from #39664 --- src/lib/es2020.intl.d.ts | 180 ++++++++++++++++++--------------------- 1 file changed, 83 insertions(+), 97 deletions(-) diff --git a/src/lib/es2020.intl.d.ts b/src/lib/es2020.intl.d.ts index cf75a593f2a0e..d33f626d2ad51 100644 --- a/src/lib/es2020.intl.d.ts +++ b/src/lib/es2020.intl.d.ts @@ -4,7 +4,6 @@ declare namespace Intl { * [Unicode BCP 47 Locale Identifiers](https://unicode.org/reports/tr35/#Unicode_Language_and_Locale_Identifiers) definition. * * [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl#locales_argument). - * */ type UnicodeBCP47LocaleIdentifier = string; @@ -12,8 +11,6 @@ declare namespace Intl { * Unit to use in the relative time internationalized message. * * [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/format#Parameters). - * - * [Specification](https://tc39.es/ecma402/#sec-singularrelativetimeunit). */ type RelativeTimeFormatUnit = | "year" | "years" @@ -30,8 +27,6 @@ declare namespace Intl { * The locale matching algorithm to use. * * [MDN](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Intl#Locale_negotiation). - * - * [Specification](https://tc39.es/ecma402/#sec-InitializeRelativeTimeFormat). */ type RelativeTimeFormatLocaleMatcher = "lookup" | "best fit"; @@ -39,8 +34,6 @@ declare namespace Intl { * The format of output message. * * [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/RelativeTimeFormat#Parameters). - * - * [Specification](https://tc39.es/ecma402/#sec-InitializeRelativeTimeFormat). */ type RelativeTimeFormatNumeric = "always" | "auto"; @@ -48,22 +41,28 @@ declare namespace Intl { * The length of the internationalized message. * * [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/RelativeTimeFormat#Parameters). - * - * [Specification](https://tc39.es/ecma402/#sec-InitializeRelativeTimeFormat). */ type RelativeTimeFormatStyle = "long" | "short" | "narrow"; + /** + * [BCP 47 language tag](http://tools.ietf.org/html/rfc5646) definition. + * + * [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl#locales_argument). + */ + type BCP47LanguageTag = string; + /** * An object with some or all of properties of `options` parameter * of `Intl.RelativeTimeFormat` constructor. * * [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/RelativeTimeFormat#Parameters). - * - * [Specification](https://tc39.es/ecma402/#sec-InitializeRelativeTimeFormat). */ interface RelativeTimeFormatOptions { + /** 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). */ localeMatcher?: RelativeTimeFormatLocaleMatcher; + /** The format of output message. */ numeric?: RelativeTimeFormatNumeric; + /** The length of the internationalized message. */ style?: RelativeTimeFormatStyle; } @@ -73,8 +72,6 @@ declare namespace Intl { * of the `Intel.RelativeTimeFormat` object * * [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/resolvedOptions#Description). - * - * [Specification](https://tc39.es/ecma402/#table-relativetimeformat-resolvedoptions-properties) */ interface ResolvedRelativeTimeFormatOptions { locale: UnicodeBCP47LocaleIdentifier; @@ -88,8 +85,6 @@ declare namespace Intl { * that can be used for custom locale-aware formatting. * * [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/formatToParts#Using_formatToParts). - * - * [Specification](https://tc39.es/ecma402/#sec-FormatRelativeTimeToParts). */ interface RelativeTimeFormatPart { type: string; @@ -106,6 +101,7 @@ declare namespace Intl { * * While this method automatically provides the correct plural forms, * the grammatical form is otherwise as neutral as possible. + * * It is the caller's responsibility to handle cut-off logic * such as deciding between displaying "in 7 days" or "in 1 week". * This API does not support relative dates involving compound units. @@ -113,68 +109,33 @@ declare namespace Intl { * * @param value - Numeric value to use in the internationalized relative time message * - * @param unit - [Unit](https://tc39.es/ecma402/#sec-singularrelativetimeunit) - * to use in the relative time internationalized message. - * Possible values are: `"year"`, `"quarter"`, `"month"`, `"week"`, - * `"day"`, `"hour"`, `"minute"`, `"second"`. - * Plural forms are also permitted. + * @param unit - [Unit](https://tc39.es/ecma402/#sec-singularrelativetimeunit) to use in the relative time internationalized message. * * @throws `RangeError` if `unit` was given something other than `unit` possible values * - * @returns Internationalized relative time message as string + * @returns {string} Internationalized relative time message as string * * [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/format). - * - * [Specification](https://tc39.es/ecma402/#sec-Intl.RelativeTimeFormat.prototype.format). */ - format( - value: number, - unit: RelativeTimeFormatUnit, - ): string; + format(value: number, unit: RelativeTimeFormatUnit): string; /** - * A version of the format method which it returns an array of objects - * which represent "parts" of the object, - * separating the formatted number into its constituent parts - * and separating it from other surrounding text. - * These objects have two properties: - * `type` a NumberFormat formatToParts type, and `value`, - * which is the String which is the component of the output. - * If a "part" came from NumberFormat, - * it will have a unit property which indicates the `unit` being formatted; - * literals which are part of the larger frame will not have this property. + * Returns an array of objects representing the relative time format in parts that can be used for custom locale-aware formatting. * * @param value - Numeric value to use in the internationalized relative time message * - * @param unit - [Unit](https://tc39.es/ecma402/#sec-singularrelativetimeunit) - * to use in the relative time internationalized message. - * Possible values are: `"year"`, `"quarter"`, `"month"`, `"week"`, - * `"day"`, `"hour"`, `"minute"`, `"second"`. - * Plural forms are also permitted. + * @param unit - [Unit](https://tc39.es/ecma402/#sec-singularrelativetimeunit) to use in the relative time internationalized message. * * @throws `RangeError` if `unit` was given something other than `unit` possible values * - * @returns Array of [FormatRelativeTimeToParts](https://tc39.es/ecma402/#sec-FormatRelativeTimeToParts) - * * [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/formatToParts). - * - * [Specification](https://tc39.es/ecma402/#sec-Intl.RelativeTimeFormat.prototype.formatToParts). */ - formatToParts( - value: number, - unit: RelativeTimeFormatUnit, - ): RelativeTimeFormatPart[]; + formatToParts(value: number, unit: RelativeTimeFormatUnit): RelativeTimeFormatPart[]; /** * Provides access to the locale and options computed during initialization of this `Intl.RelativeTimeFormat` object. * - * @returns A new object with properties reflecting the locale - * and formatting options computed during initialization - * of the `Intel.RelativeTimeFormat` object. - * * [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/resolvedOptions). - * - * [Specification](https://tc39.es/ecma402/#sec-intl.relativetimeformat.prototype.resolvedoptions) */ resolvedOptions(): ResolvedRelativeTimeFormatOptions; } @@ -187,37 +148,21 @@ declare namespace Intl { * namespace and the [ECMAScript Internationalization API](https://www.ecma-international.org/publications/standards/Ecma-402.htm). * * [Compatibility](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat#Browser_compatibility). - * - * [Polyfills](https://github.com/tc39/proposal-intl-relative-time#polyfills). */ const RelativeTimeFormat: { /** - * Constructor creates [Intl.RelativeTimeFormat](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RelativeTimeFormat) - * objects + * Creates [Intl.RelativeTimeFormat](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RelativeTimeFormat) objects * * @param locales - A string with a [BCP 47 language tag](http://tools.ietf.org/html/rfc5646), or an array of such strings. * For the general form and interpretation of the locales argument, * see the [`Intl` page](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl#Locale_identification_and_negotiation). * * @param options - An [object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/RelativeTimeFormat#Parameters) - * with some or all of options of the formatting. - * An object with some or all of the following properties: - * - `localeMatcher` - The locale matching algorithm to use. - * Possible values are `"lookup"` and `"best fit"`; the default is `"best fit"`. - * For information about this option, see [Intl page](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Intl#Locale_negotiation). - * - `numeric` - The format of output message. - * Possible values are: `"always"` (default, e.g., `1 day ago`) or `"auto"` (e.g., `yesterday`). - * The `"auto"` value allows to not always have to use numeric values in the output. - * - `style` - The length of the internationalized message. Possible values are: - * `"long"` (default, e.g., in 1 month), - * `"short"` (e.g., in 1 mo.) - * or `"narrow"` (e.g., in 1 mo.). The narrow style could be similar to the short style for some locales. + * with some or all of options of `RelativeTimeFormatOptions`. * * @returns [Intl.RelativeTimeFormat](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RelativeTimeFormat) object. * * [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/RelativeTimeFormat). - * - * [Specification](https://tc39.es/ecma402/#sec-intl-relativetimeformat-constructor). */ new( locales?: UnicodeBCP47LocaleIdentifier | UnicodeBCP47LocaleIdentifier[], @@ -235,25 +180,12 @@ declare namespace Intl { * * @param options - An [object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/RelativeTimeFormat#Parameters) * with some or all of options of the formatting. - * An object with some or all of the following properties: - * - `localeMatcher` - The locale matching algorithm to use. - * Possible values are `"lookup"` and `"best fit"`; the default is `"best fit"`. - * For information about this option, see [Intl page](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Intl#Locale_negotiation). - * - `numeric` - The format of output message. - * Possible values are: `"always"` (default, e.g., `1 day ago`) or `"auto"` (e.g., `yesterday`). - * The `"auto"` value allows to not always have to use numeric values in the output. - * - `style` - The length of the internationalized message. Possible values are: - * `"long"` (default, e.g., in 1 month), - * `"short"` (e.g., in 1 mo.) - * or `"narrow"` (e.g., in 1 mo.). The narrow style could be similar to the short style for some locales. * * @returns An array containing those of the provided locales * that are supported in date and time formatting * without having to fall back to the runtime's default locale. * * [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/supportedLocalesOf). - * - * [Specification](https://tc39.es/ecma402/#sec-Intl.RelativeTimeFormat.supportedLocalesOf). */ supportedLocalesOf( locales?: UnicodeBCP47LocaleIdentifier | UnicodeBCP47LocaleIdentifier[], @@ -262,19 +194,19 @@ declare namespace Intl { }; interface NumberFormatOptions { - compactDisplay?: string; - notation?: string; - signDisplay?: string; - unit?: string; - unitDisplay?: string; + compactDisplay?: "short" | "long"; + notation?: "standard" | "scientific" | "engineering" | "compact"; + signDisplay?: "auto" | "never" | "always"; + unit?: NumberFormatUnit; + unitDisplay?: "short" | "long" | "narrow"; } interface ResolvedNumberFormatOptions { - compactDisplay?: string; - notation?: string; - signDisplay?: string; - unit?: string; - unitDisplay?: string; + compactDisplay?: "short" | "long"; + notation?: "standard" | "scientific" | "engineering" | "compact"; + signDisplay?: "auto" | "never" | "always"; + unit?: NumberFormatUnit; + unitDisplay?: "short" | "long" | "narrow"; } interface DateTimeFormatOptions { @@ -286,4 +218,58 @@ declare namespace Intl { hourCycle?: "h11" | "h12" | "h23" | "h24"; fractionalSecondDigits?: 0 | 1 | 2 | 3; } + + type LocaleHourCycleKey = "h12" | "h23" | "h11" | "h24"; + type LocaleCollationCaseFirst = "upper" | "lower" | "false"; + + interface LocaleOptions { + /** A string containing the language, and the script and region if available. */ + baseName?: string; + /** The part of the Locale that indicates the locale's calendar era. */ + calendar?: string; + /** Flag that defines whether case is taken into account for the locale's collation rules. */ + caseFirst?: LocaleCollationCaseFirst; + /** The collation type used for sorting */ + collation?: string; + /** The time keeping format convention used by the locale. */ + hourCycle?: LocaleHourCycleKey; + /** The primary language subtag associated with the locale. */ + language?: string; + /** The numeral system used by the locale. */ + numberingSystem?: string; + /** Flag that defines whether the locale has special collation handling for numeric characters. */ + numeric?: boolean; + /** The region of the world (usually a country) associated with the locale. Possible values are region codes as defined by ISO 3166-1. */ + region?: string; + /** The script used for writing the particular language used in the locale. Possible values are script codes as defined by ISO 15924. */ + script?: string; + } + + interface Locale extends LocaleOptions { + /** Gets the most likely values for the language, script, and region of the locale based on existing values. */ + maximize(): Locale; + /** 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; + } + + /** + * Constructor creates [Intl.Locale](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale) + * objects + * + * @param tag - A string with a [BCP 47 language tag](http://tools.ietf.org/html/rfc5646). + * For the general form and interpretation of the locales argument, + * see the [`Intl` page](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl#Locale_identification_and_negotiation). + * + * @param options - An [object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/Locale#Parameters) + * with some or all of options of the locale. + * + * @returns [Intl.Locale](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale) object. + * + * [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale). + */ + const Locale: { + new (tag?: BCP47LanguageTag, options?: LocaleOptions): Locale; + }; } From 872894d6bc1f0fc539737f815713ff5a981ddd66 Mon Sep 17 00:00:00 2001 From: Orta Date: Mon, 30 Aug 2021 21:49:09 +0100 Subject: [PATCH 02/14] Handle updating es2020.intl and add es2021 for new DateTimeFormatOptions options - re: #39664 --- lib/lib.es2021.d.ts | 1 + src/lib/es2020.intl.d.ts | 26 ++++++++++++++++---------- src/lib/es2021.intl.d.ts | 9 +++++++++ src/lib/libs.json | 1 + 4 files changed, 27 insertions(+), 10 deletions(-) create mode 100644 src/lib/es2021.intl.d.ts diff --git a/lib/lib.es2021.d.ts b/lib/lib.es2021.d.ts index 1cb1e732ad858..74b5288d103b4 100644 --- a/lib/lib.es2021.d.ts +++ b/lib/lib.es2021.d.ts @@ -22,3 +22,4 @@ and limitations under the License. /// /// /// +/// diff --git a/src/lib/es2020.intl.d.ts b/src/lib/es2020.intl.d.ts index d33f626d2ad51..7fd3d05b2775e 100644 --- a/src/lib/es2020.intl.d.ts +++ b/src/lib/es2020.intl.d.ts @@ -13,16 +13,22 @@ declare namespace Intl { * [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/format#Parameters). */ type RelativeTimeFormatUnit = - | "year" | "years" - | "quarter" | "quarters" - | "month" | "months" - | "week" | "weeks" - | "day" | "days" - | "hour" | "hours" - | "minute" | "minutes" - | "second" | "seconds" - ; - + | "year" + | "years" + | "quarter" + | "quarters" + | "month" + | "months" + | "week" + | "weeks" + | "day" + | "days" + | "hour" + | "hours" + | "minute" + | "minutes" + | "second" + | "seconds"; /** * The locale matching algorithm to use. * diff --git a/src/lib/es2021.intl.d.ts b/src/lib/es2021.intl.d.ts new file mode 100644 index 0000000000000..74d0158d6f325 --- /dev/null +++ b/src/lib/es2021.intl.d.ts @@ -0,0 +1,9 @@ +declare namespace Intl { + + interface DateTimeFormatOptions { + dateStyle?: "full" | "long" | "medium" | "short"; + timeStyle?: "full" | "long" | "medium" | "short"; + dayPeriod?: "narrow" | "short" | "long"; + fractionalSecondDigits?: 0 | 1 | 2 | 3; + } +} \ No newline at end of file diff --git a/src/lib/libs.json b/src/lib/libs.json index 0eb3d7b657a34..4131d45171b23 100644 --- a/src/lib/libs.json +++ b/src/lib/libs.json @@ -51,6 +51,7 @@ "es2021.string", "es2021.promise", "es2021.weakref", + "es2021.intl", "esnext.intl", // Default libraries "es5.full", From 2656cd8a905364c60fec905aa98a90ac20017103 Mon Sep 17 00:00:00 2001 From: Orta Date: Mon, 30 Aug 2021 21:51:11 +0100 Subject: [PATCH 03/14] Extends DateTimeFormatOptions for new Intl APIs - re: #45420 --- src/lib/es2020.intl.d.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/lib/es2020.intl.d.ts b/src/lib/es2020.intl.d.ts index 7fd3d05b2775e..982957736d039 100644 --- a/src/lib/es2020.intl.d.ts +++ b/src/lib/es2020.intl.d.ts @@ -225,6 +225,13 @@ declare namespace Intl { fractionalSecondDigits?: 0 | 1 | 2 | 3; } + interface DateTimeFormatOptions { + dateStyle?: "full" | "long" | "medium" | "short"; + timeStyle?: "full" | "long" | "medium" | "short"; + dayPeriod?: "narrow" | "short" | "long"; + hourCycle?: "h11" | "h12" | "h23" | "h24"; + } + type LocaleHourCycleKey = "h12" | "h23" | "h11" | "h24"; type LocaleCollationCaseFirst = "upper" | "lower" | "false"; From f4817439843e0df4d33e1aee860a36da4b411ebf Mon Sep 17 00:00:00 2001 From: Orta Date: Mon, 30 Aug 2021 22:22:34 +0100 Subject: [PATCH 04/14] Handle migrating Intl.NumberFormat.formatToParts to es2018 (keeping esnext.intl around) --- src/lib/es2018.intl.d.ts | 9 +++++ src/lib/esnext.intl.d.ts | 11 +----- .../baselines/reference/bigintWithLib.symbols | 8 ++-- ...angeYourTargetLibraryES2016Plus.errors.txt | 36 ++++++++--------- ...NeedToChangeYourTargetLibraryES2016Plus.js | 4 +- ...oChangeYourTargetLibraryES2016Plus.symbols | 39 ++++++++++--------- ...dToChangeYourTargetLibraryES2016Plus.types | 21 +++++----- .../reference/formatToPartsBigInt.symbols | 16 ++++---- ...NeedToChangeYourTargetLibraryES2016Plus.ts | 2 +- 9 files changed, 74 insertions(+), 72 deletions(-) diff --git a/src/lib/es2018.intl.d.ts b/src/lib/es2018.intl.d.ts index 278f404646b41..4586a1dde2785 100644 --- a/src/lib/es2018.intl.d.ts +++ b/src/lib/es2018.intl.d.ts @@ -38,4 +38,13 @@ declare namespace Intl { options?: PluralRulesOptions, ): string[]; }; + + interface NumberFormatPart { + type: "compact" | "currency" | "decimal" | "exponentInteger" | "exponentMinusSign" | "exponentSeparator" | "fraction" | "group" | "infinity" | "integer" | "literal" | "minusSign" | "nan" | "plusSign" | "percentSign" | "unit" | "unknown"; + value: string; + } + + interface NumberFormat { + formatToParts(number?: number | bigint): NumberFormatPart[]; + } } diff --git a/src/lib/esnext.intl.d.ts b/src/lib/esnext.intl.d.ts index 2f2f021f8750e..99cf65b4dcb47 100644 --- a/src/lib/esnext.intl.d.ts +++ b/src/lib/esnext.intl.d.ts @@ -1,12 +1,3 @@ declare namespace Intl { - type NumberFormatPartTypes = "compact" | "currency" | "decimal" | "exponentInteger" | "exponentMinusSign" | "exponentSeparator" | "fraction" | "group" | "infinity" | "integer" | "literal" | "minusSign" | "nan" | "plusSign" | "percentSign" | "unit" | "unknown"; - - interface NumberFormatPart { - type: NumberFormatPartTypes; - value: string; - } - - interface NumberFormat { - formatToParts(number?: number | bigint): NumberFormatPart[]; - } + // Empty for now } diff --git a/tests/baselines/reference/bigintWithLib.symbols b/tests/baselines/reference/bigintWithLib.symbols index f8f7c6bb8812d..c197f9e156794 100644 --- a/tests/baselines/reference/bigintWithLib.symbols +++ b/tests/baselines/reference/bigintWithLib.symbols @@ -241,16 +241,16 @@ let z = 12n; // should emit type bigint in declaration file // Test Intl methods with new parameter type new Intl.NumberFormat("fr").format(3000n); >new Intl.NumberFormat("fr").format : Symbol(Intl.NumberFormat.format, Decl(lib.es5.d.ts, --, --), Decl(lib.es2020.bigint.d.ts, --, --)) ->Intl.NumberFormat : Symbol(Intl.NumberFormat, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2020.bigint.d.ts, --, --)) +>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, --, --)) >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, --, --)) ->NumberFormat : Symbol(Intl.NumberFormat, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2020.bigint.d.ts, --, --)) +>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, --, --)) >format : Symbol(Intl.NumberFormat.format, Decl(lib.es5.d.ts, --, --), Decl(lib.es2020.bigint.d.ts, --, --)) new Intl.NumberFormat("fr").format(bigintVal); >new Intl.NumberFormat("fr").format : Symbol(Intl.NumberFormat.format, Decl(lib.es5.d.ts, --, --), Decl(lib.es2020.bigint.d.ts, --, --)) ->Intl.NumberFormat : Symbol(Intl.NumberFormat, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2020.bigint.d.ts, --, --)) +>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, --, --)) >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, --, --)) ->NumberFormat : Symbol(Intl.NumberFormat, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2020.bigint.d.ts, --, --)) +>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, --, --)) >format : Symbol(Intl.NumberFormat.format, Decl(lib.es5.d.ts, --, --), Decl(lib.es2020.bigint.d.ts, --, --)) >bigintVal : Symbol(bigintVal, Decl(bigintWithLib.ts, 1, 3)) diff --git a/tests/baselines/reference/doYouNeedToChangeYourTargetLibraryES2016Plus.errors.txt b/tests/baselines/reference/doYouNeedToChangeYourTargetLibraryES2016Plus.errors.txt index 05d5e04b51fe3..ee42a781a6366 100644 --- a/tests/baselines/reference/doYouNeedToChangeYourTargetLibraryES2016Plus.errors.txt +++ b/tests/baselines/reference/doYouNeedToChangeYourTargetLibraryES2016Plus.errors.txt @@ -16,21 +16,21 @@ tests/cases/compiler/doYouNeedToChangeYourTargetLibraryES2016Plus.ts(20,27): err tests/cases/compiler/doYouNeedToChangeYourTargetLibraryES2016Plus.ts(21,35): error TS2583: Cannot find name 'AsyncGeneratorFunction'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2018' or later. tests/cases/compiler/doYouNeedToChangeYourTargetLibraryES2016Plus.ts(22,26): error TS2583: Cannot find name 'AsyncIterable'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2018' or later. tests/cases/compiler/doYouNeedToChangeYourTargetLibraryES2016Plus.ts(23,34): error TS2583: Cannot find name 'AsyncIterableIterator'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2018' or later. -tests/cases/compiler/doYouNeedToChangeYourTargetLibraryES2016Plus.ts(26,26): error TS2550: Property 'flat' does not exist on type 'undefined[]'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2019' or later. -tests/cases/compiler/doYouNeedToChangeYourTargetLibraryES2016Plus.ts(27,29): error TS2550: Property 'flatMap' does not exist on type 'undefined[]'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2019' or later. -tests/cases/compiler/doYouNeedToChangeYourTargetLibraryES2016Plus.ts(28,49): error TS2550: Property 'fromEntries' does not exist on type 'ObjectConstructor'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2019' or later. -tests/cases/compiler/doYouNeedToChangeYourTargetLibraryES2016Plus.ts(29,32): error TS2550: Property 'trimStart' does not exist on type '""'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2019' or later. -tests/cases/compiler/doYouNeedToChangeYourTargetLibraryES2016Plus.ts(30,30): error TS2550: Property 'trimEnd' does not exist on type '""'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2019' or later. -tests/cases/compiler/doYouNeedToChangeYourTargetLibraryES2016Plus.ts(31,31): error TS2550: Property 'trimLeft' does not exist on type '""'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2019' or later. -tests/cases/compiler/doYouNeedToChangeYourTargetLibraryES2016Plus.ts(32,32): error TS2550: Property 'trimRight' does not exist on type '""'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2019' or later. -tests/cases/compiler/doYouNeedToChangeYourTargetLibraryES2016Plus.ts(33,45): error TS2550: Property 'description' does not exist on type 'symbol'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2019' or later. -tests/cases/compiler/doYouNeedToChangeYourTargetLibraryES2016Plus.ts(36,39): error TS2550: Property 'allSettled' does not exist on type 'PromiseConstructor'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2020' or later. -tests/cases/compiler/doYouNeedToChangeYourTargetLibraryES2016Plus.ts(37,31): error TS2550: Property 'matchAll' does not exist on type '""'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2020' or later. -tests/cases/compiler/doYouNeedToChangeYourTargetLibraryES2016Plus.ts(38,47): error TS2550: Property 'matchAll' does not exist on type 'SymbolConstructor'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2020' or later. -tests/cases/compiler/doYouNeedToChangeYourTargetLibraryES2016Plus.ts(39,20): error TS2583: Cannot find name 'BigInt'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2020' or later. -tests/cases/compiler/doYouNeedToChangeYourTargetLibraryES2016Plus.ts(42,32): error TS2550: Property 'any' does not exist on type 'PromiseConstructor'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2021' or later. -tests/cases/compiler/doYouNeedToChangeYourTargetLibraryES2016Plus.ts(43,33): error TS2550: Property 'replaceAll' does not exist on type '""'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2021' or later. -tests/cases/compiler/doYouNeedToChangeYourTargetLibraryES2016Plus.ts(46,70): error TS2550: Property 'formatToParts' does not exist on type 'NumberFormat'. Do you need to change your target library? Try changing the 'lib' compiler option to 'esnext' or later. +tests/cases/compiler/doYouNeedToChangeYourTargetLibraryES2016Plus.ts(24,70): error TS2550: Property 'formatToParts' does not exist on type 'NumberFormat'. Do you need to change your target library? Try changing the 'lib' compiler option to 'esnext' or later. +tests/cases/compiler/doYouNeedToChangeYourTargetLibraryES2016Plus.ts(27,26): error TS2550: Property 'flat' does not exist on type 'undefined[]'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2019' or later. +tests/cases/compiler/doYouNeedToChangeYourTargetLibraryES2016Plus.ts(28,29): error TS2550: Property 'flatMap' does not exist on type 'undefined[]'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2019' or later. +tests/cases/compiler/doYouNeedToChangeYourTargetLibraryES2016Plus.ts(29,49): error TS2550: Property 'fromEntries' does not exist on type 'ObjectConstructor'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2019' or later. +tests/cases/compiler/doYouNeedToChangeYourTargetLibraryES2016Plus.ts(30,32): error TS2550: Property 'trimStart' does not exist on type '""'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2019' or later. +tests/cases/compiler/doYouNeedToChangeYourTargetLibraryES2016Plus.ts(31,30): error TS2550: Property 'trimEnd' does not exist on type '""'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2019' or later. +tests/cases/compiler/doYouNeedToChangeYourTargetLibraryES2016Plus.ts(32,31): error TS2550: Property 'trimLeft' does not exist on type '""'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2019' or later. +tests/cases/compiler/doYouNeedToChangeYourTargetLibraryES2016Plus.ts(33,32): error TS2550: Property 'trimRight' does not exist on type '""'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2019' or later. +tests/cases/compiler/doYouNeedToChangeYourTargetLibraryES2016Plus.ts(34,45): error TS2550: Property 'description' does not exist on type 'symbol'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2019' or later. +tests/cases/compiler/doYouNeedToChangeYourTargetLibraryES2016Plus.ts(37,39): error TS2550: Property 'allSettled' does not exist on type 'PromiseConstructor'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2020' or later. +tests/cases/compiler/doYouNeedToChangeYourTargetLibraryES2016Plus.ts(38,31): error TS2550: Property 'matchAll' does not exist on type '""'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2020' or later. +tests/cases/compiler/doYouNeedToChangeYourTargetLibraryES2016Plus.ts(39,47): error TS2550: Property 'matchAll' does not exist on type 'SymbolConstructor'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2020' or later. +tests/cases/compiler/doYouNeedToChangeYourTargetLibraryES2016Plus.ts(40,20): error TS2583: Cannot find name 'BigInt'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2020' or later. +tests/cases/compiler/doYouNeedToChangeYourTargetLibraryES2016Plus.ts(43,32): error TS2550: Property 'any' does not exist on type 'PromiseConstructor'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2021' or later. +tests/cases/compiler/doYouNeedToChangeYourTargetLibraryES2016Plus.ts(44,33): error TS2550: Property 'replaceAll' does not exist on type '""'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2021' or later. ==== tests/cases/compiler/doYouNeedToChangeYourTargetLibraryES2016Plus.ts (33 errors) ==== @@ -93,6 +93,9 @@ tests/cases/compiler/doYouNeedToChangeYourTargetLibraryES2016Plus.ts(46,70): err const testAsyncIterableIterator: AsyncIterableIterator = null as any; ~~~~~~~~~~~~~~~~~~~~~ !!! error TS2583: Cannot find name 'AsyncIterableIterator'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2018' or later. + const testNumberFormatFormatToParts = new Intl.NumberFormat("en-US").formatToParts(); + ~~~~~~~~~~~~~ +!!! error TS2550: Property 'formatToParts' does not exist on type 'NumberFormat'. Do you need to change your target library? Try changing the 'lib' compiler option to 'esnext' or later. // es2019 const testArrayFlat = [].flat(); @@ -143,7 +146,4 @@ tests/cases/compiler/doYouNeedToChangeYourTargetLibraryES2016Plus.ts(46,70): err !!! error TS2550: Property 'replaceAll' does not exist on type '""'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2021' or later. // esnext - const testNumberFormatFormatToParts = new Intl.NumberFormat("en-US").formatToParts(); - ~~~~~~~~~~~~~ -!!! error TS2550: Property 'formatToParts' does not exist on type 'NumberFormat'. Do you need to change your target library? Try changing the 'lib' compiler option to 'esnext' or later. \ No newline at end of file diff --git a/tests/baselines/reference/doYouNeedToChangeYourTargetLibraryES2016Plus.js b/tests/baselines/reference/doYouNeedToChangeYourTargetLibraryES2016Plus.js index 0a4f15227b782..c8e0b37b9fc53 100644 --- a/tests/baselines/reference/doYouNeedToChangeYourTargetLibraryES2016Plus.js +++ b/tests/baselines/reference/doYouNeedToChangeYourTargetLibraryES2016Plus.js @@ -22,6 +22,7 @@ const testAsyncGenerator: AsyncGenerator = null as any; const testAsyncGeneratorFunction: AsyncGeneratorFunction = null as any; const testAsyncIterable: AsyncIterable = null as any; const testAsyncIterableIterator: AsyncIterableIterator = null as any; +const testNumberFormatFormatToParts = new Intl.NumberFormat("en-US").formatToParts(); // es2019 const testArrayFlat = [].flat(); @@ -44,7 +45,6 @@ const testPromiseAny = Promise.any([]); const testStringReplaceAll = "".replaceAll(); // esnext -const testNumberFormatFormatToParts = new Intl.NumberFormat("en-US").formatToParts(); //// [doYouNeedToChangeYourTargetLibraryES2016Plus.js] @@ -69,6 +69,7 @@ var testAsyncGenerator = null; var testAsyncGeneratorFunction = null; var testAsyncIterable = null; var testAsyncIterableIterator = null; +var testNumberFormatFormatToParts = new Intl.NumberFormat("en-US").formatToParts(); // es2019 var testArrayFlat = [].flat(); var testArrayFlatMap = [].flatMap(); @@ -87,4 +88,3 @@ var testBigInt = BigInt(123); var testPromiseAny = Promise.any([]); var testStringReplaceAll = "".replaceAll(); // esnext -var testNumberFormatFormatToParts = new Intl.NumberFormat("en-US").formatToParts(); diff --git a/tests/baselines/reference/doYouNeedToChangeYourTargetLibraryES2016Plus.symbols b/tests/baselines/reference/doYouNeedToChangeYourTargetLibraryES2016Plus.symbols index 060c494e30149..5da8f75b73858 100644 --- a/tests/baselines/reference/doYouNeedToChangeYourTargetLibraryES2016Plus.symbols +++ b/tests/baselines/reference/doYouNeedToChangeYourTargetLibraryES2016Plus.symbols @@ -69,60 +69,61 @@ const testAsyncIterable: AsyncIterable = null as any; const testAsyncIterableIterator: AsyncIterableIterator = null as any; >testAsyncIterableIterator : Symbol(testAsyncIterableIterator, Decl(doYouNeedToChangeYourTargetLibraryES2016Plus.ts, 22, 5)) +const testNumberFormatFormatToParts = new Intl.NumberFormat("en-US").formatToParts(); +>testNumberFormatFormatToParts : Symbol(testNumberFormatFormatToParts, Decl(doYouNeedToChangeYourTargetLibraryES2016Plus.ts, 23, 5)) +>Intl.NumberFormat : Symbol(Intl.NumberFormat, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) +>Intl : Symbol(Intl, Decl(lib.es5.d.ts, --, --)) +>NumberFormat : Symbol(Intl.NumberFormat, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) + // es2019 const testArrayFlat = [].flat(); ->testArrayFlat : Symbol(testArrayFlat, Decl(doYouNeedToChangeYourTargetLibraryES2016Plus.ts, 25, 5)) +>testArrayFlat : Symbol(testArrayFlat, Decl(doYouNeedToChangeYourTargetLibraryES2016Plus.ts, 26, 5)) const testArrayFlatMap = [].flatMap(); ->testArrayFlatMap : Symbol(testArrayFlatMap, Decl(doYouNeedToChangeYourTargetLibraryES2016Plus.ts, 26, 5)) +>testArrayFlatMap : Symbol(testArrayFlatMap, Decl(doYouNeedToChangeYourTargetLibraryES2016Plus.ts, 27, 5)) const testObjectConstructorFromEntries = Object.fromEntries({}); ->testObjectConstructorFromEntries : Symbol(testObjectConstructorFromEntries, Decl(doYouNeedToChangeYourTargetLibraryES2016Plus.ts, 27, 5)) +>testObjectConstructorFromEntries : Symbol(testObjectConstructorFromEntries, Decl(doYouNeedToChangeYourTargetLibraryES2016Plus.ts, 28, 5)) >Object : Symbol(Object, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) const testStringTrimStart = "".trimStart(); ->testStringTrimStart : Symbol(testStringTrimStart, Decl(doYouNeedToChangeYourTargetLibraryES2016Plus.ts, 28, 5)) +>testStringTrimStart : Symbol(testStringTrimStart, Decl(doYouNeedToChangeYourTargetLibraryES2016Plus.ts, 29, 5)) const testStringTrimEnd = "".trimEnd(); ->testStringTrimEnd : Symbol(testStringTrimEnd, Decl(doYouNeedToChangeYourTargetLibraryES2016Plus.ts, 29, 5)) +>testStringTrimEnd : Symbol(testStringTrimEnd, Decl(doYouNeedToChangeYourTargetLibraryES2016Plus.ts, 30, 5)) const testStringTrimLeft = "".trimLeft(); ->testStringTrimLeft : Symbol(testStringTrimLeft, Decl(doYouNeedToChangeYourTargetLibraryES2016Plus.ts, 30, 5)) +>testStringTrimLeft : Symbol(testStringTrimLeft, Decl(doYouNeedToChangeYourTargetLibraryES2016Plus.ts, 31, 5)) const testStringTrimRight = "".trimRight(); ->testStringTrimRight : Symbol(testStringTrimRight, Decl(doYouNeedToChangeYourTargetLibraryES2016Plus.ts, 31, 5)) +>testStringTrimRight : Symbol(testStringTrimRight, Decl(doYouNeedToChangeYourTargetLibraryES2016Plus.ts, 32, 5)) const testSymbolDescription = Symbol("foo").description; ->testSymbolDescription : Symbol(testSymbolDescription, Decl(doYouNeedToChangeYourTargetLibraryES2016Plus.ts, 32, 5)) +>testSymbolDescription : Symbol(testSymbolDescription, Decl(doYouNeedToChangeYourTargetLibraryES2016Plus.ts, 33, 5)) >Symbol : Symbol(Symbol, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --)) // es2020 const testPromiseAllSettled = Promise.allSettled([]); ->testPromiseAllSettled : Symbol(testPromiseAllSettled, Decl(doYouNeedToChangeYourTargetLibraryES2016Plus.ts, 35, 5)) +>testPromiseAllSettled : Symbol(testPromiseAllSettled, Decl(doYouNeedToChangeYourTargetLibraryES2016Plus.ts, 36, 5)) >Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --)) const testStringMatchAll = "".matchAll(); ->testStringMatchAll : Symbol(testStringMatchAll, Decl(doYouNeedToChangeYourTargetLibraryES2016Plus.ts, 36, 5)) +>testStringMatchAll : Symbol(testStringMatchAll, Decl(doYouNeedToChangeYourTargetLibraryES2016Plus.ts, 37, 5)) const testRegExpMatchAll = /matchAll/g[Symbol.matchAll]("matchAll"); ->testRegExpMatchAll : Symbol(testRegExpMatchAll, Decl(doYouNeedToChangeYourTargetLibraryES2016Plus.ts, 37, 5)) +>testRegExpMatchAll : Symbol(testRegExpMatchAll, Decl(doYouNeedToChangeYourTargetLibraryES2016Plus.ts, 38, 5)) >Symbol : Symbol(Symbol, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --)) const testBigInt = BigInt(123); ->testBigInt : Symbol(testBigInt, Decl(doYouNeedToChangeYourTargetLibraryES2016Plus.ts, 38, 5)) +>testBigInt : Symbol(testBigInt, Decl(doYouNeedToChangeYourTargetLibraryES2016Plus.ts, 39, 5)) // es2021 const testPromiseAny = Promise.any([]); ->testPromiseAny : Symbol(testPromiseAny, Decl(doYouNeedToChangeYourTargetLibraryES2016Plus.ts, 41, 5)) +>testPromiseAny : Symbol(testPromiseAny, Decl(doYouNeedToChangeYourTargetLibraryES2016Plus.ts, 42, 5)) >Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --)) const testStringReplaceAll = "".replaceAll(); ->testStringReplaceAll : Symbol(testStringReplaceAll, Decl(doYouNeedToChangeYourTargetLibraryES2016Plus.ts, 42, 5)) +>testStringReplaceAll : Symbol(testStringReplaceAll, Decl(doYouNeedToChangeYourTargetLibraryES2016Plus.ts, 43, 5)) // esnext -const testNumberFormatFormatToParts = new Intl.NumberFormat("en-US").formatToParts(); ->testNumberFormatFormatToParts : Symbol(testNumberFormatFormatToParts, Decl(doYouNeedToChangeYourTargetLibraryES2016Plus.ts, 45, 5)) ->Intl.NumberFormat : Symbol(Intl.NumberFormat, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) ->Intl : Symbol(Intl, Decl(lib.es5.d.ts, --, --)) ->NumberFormat : Symbol(Intl.NumberFormat, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) diff --git a/tests/baselines/reference/doYouNeedToChangeYourTargetLibraryES2016Plus.types b/tests/baselines/reference/doYouNeedToChangeYourTargetLibraryES2016Plus.types index 95bd9e9fb15b6..815e4352d61fc 100644 --- a/tests/baselines/reference/doYouNeedToChangeYourTargetLibraryES2016Plus.types +++ b/tests/baselines/reference/doYouNeedToChangeYourTargetLibraryES2016Plus.types @@ -147,6 +147,17 @@ const testAsyncIterableIterator: AsyncIterableIterator = null as any; >null as any : any >null : null +const testNumberFormatFormatToParts = new Intl.NumberFormat("en-US").formatToParts(); +>testNumberFormatFormatToParts : any +>new Intl.NumberFormat("en-US").formatToParts() : any +>new Intl.NumberFormat("en-US").formatToParts : any +>new Intl.NumberFormat("en-US") : Intl.NumberFormat +>Intl.NumberFormat : { (locales?: string | string[], options?: Intl.NumberFormatOptions): Intl.NumberFormat; new (locales?: string | string[], options?: Intl.NumberFormatOptions): Intl.NumberFormat; supportedLocalesOf(locales: string | string[], options?: Intl.NumberFormatOptions): string[]; } +>Intl : typeof Intl +>NumberFormat : { (locales?: string | string[], options?: Intl.NumberFormatOptions): Intl.NumberFormat; new (locales?: string | string[], options?: Intl.NumberFormatOptions): Intl.NumberFormat; supportedLocalesOf(locales: string | string[], options?: Intl.NumberFormatOptions): string[]; } +>"en-US" : "en-US" +>formatToParts : any + // es2019 const testArrayFlat = [].flat(); >testArrayFlat : any @@ -255,14 +266,4 @@ const testStringReplaceAll = "".replaceAll(); >replaceAll : any // esnext -const testNumberFormatFormatToParts = new Intl.NumberFormat("en-US").formatToParts(); ->testNumberFormatFormatToParts : any ->new Intl.NumberFormat("en-US").formatToParts() : any ->new Intl.NumberFormat("en-US").formatToParts : any ->new Intl.NumberFormat("en-US") : Intl.NumberFormat ->Intl.NumberFormat : { (locales?: string | string[], options?: Intl.NumberFormatOptions): Intl.NumberFormat; new (locales?: string | string[], options?: Intl.NumberFormatOptions): Intl.NumberFormat; supportedLocalesOf(locales: string | string[], options?: Intl.NumberFormatOptions): string[]; } ->Intl : typeof Intl ->NumberFormat : { (locales?: string | string[], options?: Intl.NumberFormatOptions): Intl.NumberFormat; new (locales?: string | string[], options?: Intl.NumberFormatOptions): Intl.NumberFormat; supportedLocalesOf(locales: string | string[], options?: Intl.NumberFormatOptions): string[]; } ->"en-US" : "en-US" ->formatToParts : any diff --git a/tests/baselines/reference/formatToPartsBigInt.symbols b/tests/baselines/reference/formatToPartsBigInt.symbols index f3037bfef10ed..84b618f140805 100644 --- a/tests/baselines/reference/formatToPartsBigInt.symbols +++ b/tests/baselines/reference/formatToPartsBigInt.symbols @@ -3,17 +3,17 @@ // Test Intl methods with new parameter type new Intl.NumberFormat("fr").formatToParts(3000n); ->new Intl.NumberFormat("fr").formatToParts : Symbol(Intl.NumberFormat.formatToParts, Decl(lib.esnext.intl.d.ts, --, --)) ->Intl.NumberFormat : Symbol(Intl.NumberFormat, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2020.bigint.d.ts, --, --), Decl(lib.esnext.intl.d.ts, --, --)) +>new Intl.NumberFormat("fr").formatToParts : Symbol(Intl.NumberFormat.formatToParts, Decl(lib.es2018.intl.d.ts, --, --)) +>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, --, --)) >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, --, --) ... and 1 more) ->NumberFormat : Symbol(Intl.NumberFormat, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2020.bigint.d.ts, --, --), Decl(lib.esnext.intl.d.ts, --, --)) ->formatToParts : Symbol(Intl.NumberFormat.formatToParts, Decl(lib.esnext.intl.d.ts, --, --)) +>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, --, --)) +>formatToParts : Symbol(Intl.NumberFormat.formatToParts, Decl(lib.es2018.intl.d.ts, --, --)) new Intl.NumberFormat("fr").formatToParts(BigInt(123)); ->new Intl.NumberFormat("fr").formatToParts : Symbol(Intl.NumberFormat.formatToParts, Decl(lib.esnext.intl.d.ts, --, --)) ->Intl.NumberFormat : Symbol(Intl.NumberFormat, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2020.bigint.d.ts, --, --), Decl(lib.esnext.intl.d.ts, --, --)) +>new Intl.NumberFormat("fr").formatToParts : Symbol(Intl.NumberFormat.formatToParts, Decl(lib.es2018.intl.d.ts, --, --)) +>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, --, --)) >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, --, --) ... and 1 more) ->NumberFormat : Symbol(Intl.NumberFormat, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2020.bigint.d.ts, --, --), Decl(lib.esnext.intl.d.ts, --, --)) ->formatToParts : Symbol(Intl.NumberFormat.formatToParts, Decl(lib.esnext.intl.d.ts, --, --)) +>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, --, --)) +>formatToParts : Symbol(Intl.NumberFormat.formatToParts, Decl(lib.es2018.intl.d.ts, --, --)) >BigInt : Symbol(BigInt, Decl(lib.es2020.bigint.d.ts, --, --), Decl(lib.es2020.bigint.d.ts, --, --)) diff --git a/tests/cases/compiler/doYouNeedToChangeYourTargetLibraryES2016Plus.ts b/tests/cases/compiler/doYouNeedToChangeYourTargetLibraryES2016Plus.ts index fdff373fee882..0c754c740c4a5 100644 --- a/tests/cases/compiler/doYouNeedToChangeYourTargetLibraryES2016Plus.ts +++ b/tests/cases/compiler/doYouNeedToChangeYourTargetLibraryES2016Plus.ts @@ -23,6 +23,7 @@ const testAsyncGenerator: AsyncGenerator = null as any; const testAsyncGeneratorFunction: AsyncGeneratorFunction = null as any; const testAsyncIterable: AsyncIterable = null as any; const testAsyncIterableIterator: AsyncIterableIterator = null as any; +const testNumberFormatFormatToParts = new Intl.NumberFormat("en-US").formatToParts(); // es2019 const testArrayFlat = [].flat(); @@ -45,4 +46,3 @@ const testPromiseAny = Promise.any([]); const testStringReplaceAll = "".replaceAll(); // esnext -const testNumberFormatFormatToParts = new Intl.NumberFormat("en-US").formatToParts(); From 2e2f7550bf8d1ad93d7079ab29502f0fe031b23d Mon Sep 17 00:00:00 2001 From: Orta Date: Mon, 30 Aug 2021 22:38:30 +0100 Subject: [PATCH 05/14] Adds Intl.DisplayNames to es2020 - re: #44022 --- src/lib/es2020.intl.d.ts | 79 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 73 insertions(+), 6 deletions(-) diff --git a/src/lib/es2020.intl.d.ts b/src/lib/es2020.intl.d.ts index 982957736d039..4ca029f749d47 100644 --- a/src/lib/es2020.intl.d.ts +++ b/src/lib/es2020.intl.d.ts @@ -29,6 +29,7 @@ declare namespace Intl { | "minutes" | "second" | "seconds"; + /** * The locale matching algorithm to use. * @@ -75,7 +76,7 @@ declare namespace Intl { /** * An object with properties reflecting the locale * and formatting options computed during initialization - * of the `Intel.RelativeTimeFormat` object + * of the `Intl.RelativeTimeFormat` object * * [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/resolvedOptions#Description). */ @@ -150,9 +151,6 @@ declare namespace Intl { * The [`Intl.RelativeTimeFormat`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/RelativeTimeFormat) * object is a constructor for objects that enable language-sensitive relative time formatting. * - * Part of [Intl object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl) - * namespace and the [ECMAScript Internationalization API](https://www.ecma-international.org/publications/standards/Ecma-402.htm). - * * [Compatibility](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat#Browser_compatibility). */ const RelativeTimeFormat: { @@ -275,8 +273,7 @@ declare namespace Intl { * For the general form and interpretation of the locales argument, * see the [`Intl` page](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl#Locale_identification_and_negotiation). * - * @param options - An [object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/Locale#Parameters) - * with some or all of options of the locale. + * @param options - An [object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/Locale#Parameters) with some or all of options of the locale. * * @returns [Intl.Locale](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale) object. * @@ -285,4 +282,74 @@ declare namespace Intl { const Locale: { new (tag?: BCP47LanguageTag, options?: LocaleOptions): Locale; }; + + interface DisplayNamesOptions { + localeMatcher: RelativeTimeFormatLocaleMatcher; + style: RelativeTimeFormatStyle; + type: "language" | "region" | "script" | "currency"; + fallback: "code" | "none"; + } + + interface DisplayNames { + /** + * Receives a code and returns a string based on the locale and options provided when instantiating + * [`Intl.DisplayNames()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames) + * + * @param code The `code` to provide depends on the `type` passed to display name during creation: + * - If the type is `"region"`, code should be either an [ISO-3166 two letters region code](https://www.iso.org/iso-3166-country-codes.html), + * or a [three digits UN M49 Geographic Regions](https://unstats.un.org/unsd/methodology/m49/). + * - If the type is `"script"`, code should be an [ISO-15924 four letters script code](https://unicode.org/iso15924/iso15924-codes.html). + * - If the type is `"language"`, code should be a `languageCode` ["-" `scriptCode`] ["-" `regionCode` ] *("-" `variant` ) + * subsequence of the unicode_language_id grammar in [UTS 35's Unicode Language and Locale Identifiers grammar](https://unicode.org/reports/tr35/#Unicode_language_identifier). + * `languageCode` is either a two letters ISO 639-1 language code or a three letters ISO 639-2 language code. + * - If the type is `"currency"`, code should be a [3-letter ISO 4217 currency code](https://www.iso.org/iso-4217-currency-codes.html). + * + * [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/of). + */ + of(code: string): string; + /** + * Returns a new object with properties reflecting the locale and style formatting options computed during the construction of the current + * [`Intl/DisplayNames`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames) object. + * + * [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/resolvedOptions). + */ + resolvedOptions(): DisplayNamesOptions; + } + + /** + * The [`Intl.DisplayNames()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames) + * object enables the consistent translation of language, region and script display names. + * + * [Compatibility](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames#browser_compatibility). + */ + const DisplayNames: { + prototype: DisplayNames; + + /** + * @param locales A string with a BCP 47 language tag, or an array of such strings. + * For the general form and interpretation of the `locales` argument, see the [Intl](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl#locale_identification_and_negotiation) + * page. + * + * @param options An object for setting up a display name. + * + * [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/DisplayNames). + */ + new(locales?: BCP47LanguageTag | BCP47LanguageTag[], options?: Partial): DisplayNames; + + /** + * Returns an array containing those of the provided locales that are supported in display names without having to fall back to the runtime's default locale. + * + * @param locales A string with a BCP 47 language tag, or an array of such strings. + * For the general form and interpretation of the `locales` argument, see the [Intl](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl#locale_identification_and_negotiation) + * page. + * + * @param options An object with a locale matcher. + * + * @returns An array of strings representing a subset of the given locale tags that are supported in display names without having to fall back to the runtime's default locale. + * + * [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/supportedLocalesOf). + */ + supportedLocalesOf(locales: BCP47LanguageTag | BCP47LanguageTag[], options: {localeMatcher: RelativeTimeFormatLocaleMatcher}): BCP47LanguageTag[]; + }; + } From df508a0ed50cde11b92d4b0726030e1dde9d0384 Mon Sep 17 00:00:00 2001 From: Orta Date: Mon, 30 Aug 2021 22:42:42 +0100 Subject: [PATCH 06/14] Remove attributes added in es2021 from es2020 - re: #42944 --- src/lib/es2020.intl.d.ts | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/lib/es2020.intl.d.ts b/src/lib/es2020.intl.d.ts index 4ca029f749d47..405eeaff8d48d 100644 --- a/src/lib/es2020.intl.d.ts +++ b/src/lib/es2020.intl.d.ts @@ -214,19 +214,15 @@ declare namespace Intl { } interface DateTimeFormatOptions { - dateStyle?: "full" | "long" | "medium" | "short"; - timeStyle?: "full" | "long" | "medium" | "short"; calendar?: string; dayPeriod?: "narrow" | "short" | "long"; numberingSystem?: string; hourCycle?: "h11" | "h12" | "h23" | "h24"; - fractionalSecondDigits?: 0 | 1 | 2 | 3; } interface DateTimeFormatOptions { dateStyle?: "full" | "long" | "medium" | "short"; timeStyle?: "full" | "long" | "medium" | "short"; - dayPeriod?: "narrow" | "short" | "long"; hourCycle?: "h11" | "h12" | "h23" | "h24"; } From ff94585ec0bfcad75b305dd493f12cab695626d9 Mon Sep 17 00:00:00 2001 From: Orta Date: Mon, 30 Aug 2021 22:43:49 +0100 Subject: [PATCH 07/14] Add a reference to es2021 in the command line parser --- src/compiler/commandLineParser.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index 8ea829eaad5b2..780c9af46ee87 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -71,6 +71,7 @@ namespace ts { ["es2021.promise", "lib.es2021.promise.d.ts"], ["es2021.string", "lib.es2021.string.d.ts"], ["es2021.weakref", "lib.es2021.weakref.d.ts"], + ["es2021.intl", "lib.es2021.intl.d.ts"], ["esnext.array", "lib.es2019.array.d.ts"], ["esnext.symbol", "lib.es2019.symbol.d.ts"], ["esnext.asynciterable", "lib.es2018.asynciterable.d.ts"], From 9edc1f745130185fe3463c24daae8d5a4b54d792 Mon Sep 17 00:00:00 2001 From: Orta Date: Mon, 30 Aug 2021 23:02:53 +0100 Subject: [PATCH 08/14] Adds some docs about the lib files --- src/lib/README.md | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/lib/README.md b/src/lib/README.md index 1b51e2cfc64ab..136225dde63a6 100644 --- a/src/lib/README.md +++ b/src/lib/README.md @@ -1,8 +1,26 @@ # Read this! -The files within this directory are used to generate `lib.d.ts` and `lib.es6.d.ts`. +The files within this directory are copied and deployed with TypeScript as the set of APIs available as a part of the JavaScript language. + +There are three main domains of APIs in `src/lib`: + + - **ECMAScript language features** - e.g. JavaScript APIs like functions on Array etc which are documented in [ECMA-262](https://tc39.es/ecma262/) + - **DOM APIs** - e.g. APIs which are available in Web Browsers + - **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/) + +Finished proposals, anything in here can safely be added according to the years the proposal was added: + + - [JavaScript](https://github.com/tc39/proposals/blob/master/finished-proposals.md) + - [Intl](https://github.com/tc39/proposals/blob/master/ecma402/finished-proposals.md) + +## How do we figure out when to add something? + +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 usually means the proposal is at stage 3 or later. + +For the DOM APIs, which are a bit more free-form we have ask that APIs are available (un-prefixed/flagged) in at least 2 browser _engines_ (e.g. not just 2 chromium browsers.) ## Generated files -Any files ending in `.generated.d.ts` aren't meant to be edited by hand. +The DOM files ending in `.generated.d.ts` aren't meant to be edited by hand. + 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). From 5f67f651e0af34f4c863870afa5599a2a3a1605c Mon Sep 17 00:00:00 2001 From: Orta Date: Tue, 31 Aug 2021 09:52:50 +0100 Subject: [PATCH 09/14] Baselines --- .../initial-build/does-not-add-color-when-NO_COLOR-is-set.js | 2 +- ...ent_OutputsSkipped-when-host-can't-provide-terminal-width.js | 2 +- ...ow-help-with-ExitStatus.DiagnosticsPresent_OutputsSkipped.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/baselines/reference/tsc/runWithoutArgs/initial-build/does-not-add-color-when-NO_COLOR-is-set.js b/tests/baselines/reference/tsc/runWithoutArgs/initial-build/does-not-add-color-when-NO_COLOR-is-set.js index 339c4f290485a..76887a62a286a 100644 --- a/tests/baselines/reference/tsc/runWithoutArgs/initial-build/does-not-add-color-when-NO_COLOR-is-set.js +++ b/tests/baselines/reference/tsc/runWithoutArgs/initial-build/does-not-add-color-when-NO_COLOR-is-set.js @@ -77,7 +77,7 @@ one of: none, commonjs, amd, system, umd, es6, es2015, es2020, esnext --lib Specify a set of bundled library declaration files that describe the target runtime environment. -one or more: es5, es6, es2015, es7, es2016, es2017, es2018, es2019, es2020, es2021, esnext, dom, dom.iterable, webworker, webworker.importscripts, webworker.iterable, scripthost, es2015.core, es2015.collection, es2015.generator, es2015.iterable, es2015.promise, es2015.proxy, es2015.reflect, es2015.symbol, es2015.symbol.wellknown, es2016.array.include, es2017.object, es2017.sharedmemory, es2017.string, es2017.intl, es2017.typedarrays, es2018.asyncgenerator, es2018.asynciterable, es2018.intl, es2018.promise, es2018.regexp, es2019.array, es2019.object, es2019.string, es2019.symbol, es2020.bigint, es2020.promise, es2020.sharedmemory, es2020.string, es2020.symbol.wellknown, es2020.intl, es2021.promise, es2021.string, es2021.weakref, esnext.array, esnext.symbol, esnext.asynciterable, esnext.intl, esnext.bigint, esnext.string, esnext.promise, esnext.weakref +one or more: es5, es6, es2015, es7, es2016, es2017, es2018, es2019, es2020, es2021, esnext, dom, dom.iterable, webworker, webworker.importscripts, webworker.iterable, scripthost, es2015.core, es2015.collection, es2015.generator, es2015.iterable, es2015.promise, es2015.proxy, es2015.reflect, es2015.symbol, es2015.symbol.wellknown, es2016.array.include, es2017.object, es2017.sharedmemory, es2017.string, es2017.intl, es2017.typedarrays, es2018.asyncgenerator, es2018.asynciterable, es2018.intl, es2018.promise, es2018.regexp, es2019.array, es2019.object, es2019.string, es2019.symbol, es2020.bigint, es2020.promise, es2020.sharedmemory, es2020.string, es2020.symbol.wellknown, es2020.intl, es2021.promise, es2021.string, es2021.weakref, es2021.intl, esnext.array, esnext.symbol, esnext.asynciterable, esnext.intl, esnext.bigint, esnext.string, esnext.promise, esnext.weakref --allowJs Allow JavaScript files to be a part of your program. Use the `checkJS` option to get errors from these files. diff --git a/tests/baselines/reference/tsc/runWithoutArgs/initial-build/show-help-with-ExitStatus.DiagnosticsPresent_OutputsSkipped-when-host-can't-provide-terminal-width.js b/tests/baselines/reference/tsc/runWithoutArgs/initial-build/show-help-with-ExitStatus.DiagnosticsPresent_OutputsSkipped-when-host-can't-provide-terminal-width.js index 02de5f847961e..3965dcaec9704 100644 --- a/tests/baselines/reference/tsc/runWithoutArgs/initial-build/show-help-with-ExitStatus.DiagnosticsPresent_OutputsSkipped-when-host-can't-provide-terminal-width.js +++ b/tests/baselines/reference/tsc/runWithoutArgs/initial-build/show-help-with-ExitStatus.DiagnosticsPresent_OutputsSkipped-when-host-can't-provide-terminal-width.js @@ -77,7 +77,7 @@ one of: none, commonjs, amd, system, umd, es6, es2015, es2020, esnext --lib Specify a set of bundled library declaration files that describe the target runtime environment. -one or more: es5, es6, es2015, es7, es2016, es2017, es2018, es2019, es2020, es2021, esnext, dom, dom.iterable, webworker, webworker.importscripts, webworker.iterable, scripthost, es2015.core, es2015.collection, es2015.generator, es2015.iterable, es2015.promise, es2015.proxy, es2015.reflect, es2015.symbol, es2015.symbol.wellknown, es2016.array.include, es2017.object, es2017.sharedmemory, es2017.string, es2017.intl, es2017.typedarrays, es2018.asyncgenerator, es2018.asynciterable, es2018.intl, es2018.promise, es2018.regexp, es2019.array, es2019.object, es2019.string, es2019.symbol, es2020.bigint, es2020.promise, es2020.sharedmemory, es2020.string, es2020.symbol.wellknown, es2020.intl, es2021.promise, es2021.string, es2021.weakref, esnext.array, esnext.symbol, esnext.asynciterable, esnext.intl, esnext.bigint, esnext.string, esnext.promise, esnext.weakref +one or more: es5, es6, es2015, es7, es2016, es2017, es2018, es2019, es2020, es2021, esnext, dom, dom.iterable, webworker, webworker.importscripts, webworker.iterable, scripthost, es2015.core, es2015.collection, es2015.generator, es2015.iterable, es2015.promise, es2015.proxy, es2015.reflect, es2015.symbol, es2015.symbol.wellknown, es2016.array.include, es2017.object, es2017.sharedmemory, es2017.string, es2017.intl, es2017.typedarrays, es2018.asyncgenerator, es2018.asynciterable, es2018.intl, es2018.promise, es2018.regexp, es2019.array, es2019.object, es2019.string, es2019.symbol, es2020.bigint, es2020.promise, es2020.sharedmemory, es2020.string, es2020.symbol.wellknown, es2020.intl, es2021.promise, es2021.string, es2021.weakref, es2021.intl, esnext.array, esnext.symbol, esnext.asynciterable, esnext.intl, esnext.bigint, esnext.string, esnext.promise, esnext.weakref --allowJs Allow JavaScript files to be a part of your program. Use the `checkJS` option to get errors from these files. diff --git a/tests/baselines/reference/tsc/runWithoutArgs/initial-build/show-help-with-ExitStatus.DiagnosticsPresent_OutputsSkipped.js b/tests/baselines/reference/tsc/runWithoutArgs/initial-build/show-help-with-ExitStatus.DiagnosticsPresent_OutputsSkipped.js index 02de5f847961e..3965dcaec9704 100644 --- a/tests/baselines/reference/tsc/runWithoutArgs/initial-build/show-help-with-ExitStatus.DiagnosticsPresent_OutputsSkipped.js +++ b/tests/baselines/reference/tsc/runWithoutArgs/initial-build/show-help-with-ExitStatus.DiagnosticsPresent_OutputsSkipped.js @@ -77,7 +77,7 @@ one of: none, commonjs, amd, system, umd, es6, es2015, es2020, esnext --lib Specify a set of bundled library declaration files that describe the target runtime environment. -one or more: es5, es6, es2015, es7, es2016, es2017, es2018, es2019, es2020, es2021, esnext, dom, dom.iterable, webworker, webworker.importscripts, webworker.iterable, scripthost, es2015.core, es2015.collection, es2015.generator, es2015.iterable, es2015.promise, es2015.proxy, es2015.reflect, es2015.symbol, es2015.symbol.wellknown, es2016.array.include, es2017.object, es2017.sharedmemory, es2017.string, es2017.intl, es2017.typedarrays, es2018.asyncgenerator, es2018.asynciterable, es2018.intl, es2018.promise, es2018.regexp, es2019.array, es2019.object, es2019.string, es2019.symbol, es2020.bigint, es2020.promise, es2020.sharedmemory, es2020.string, es2020.symbol.wellknown, es2020.intl, es2021.promise, es2021.string, es2021.weakref, esnext.array, esnext.symbol, esnext.asynciterable, esnext.intl, esnext.bigint, esnext.string, esnext.promise, esnext.weakref +one or more: es5, es6, es2015, es7, es2016, es2017, es2018, es2019, es2020, es2021, esnext, dom, dom.iterable, webworker, webworker.importscripts, webworker.iterable, scripthost, es2015.core, es2015.collection, es2015.generator, es2015.iterable, es2015.promise, es2015.proxy, es2015.reflect, es2015.symbol, es2015.symbol.wellknown, es2016.array.include, es2017.object, es2017.sharedmemory, es2017.string, es2017.intl, es2017.typedarrays, es2018.asyncgenerator, es2018.asynciterable, es2018.intl, es2018.promise, es2018.regexp, es2019.array, es2019.object, es2019.string, es2019.symbol, es2020.bigint, es2020.promise, es2020.sharedmemory, es2020.string, es2020.symbol.wellknown, es2020.intl, es2021.promise, es2021.string, es2021.weakref, es2021.intl, esnext.array, esnext.symbol, esnext.asynciterable, esnext.intl, esnext.bigint, esnext.string, esnext.promise, esnext.weakref --allowJs Allow JavaScript files to be a part of your program. Use the `checkJS` option to get errors from these files. From 689bf6f4be4bf7d66ef38933e8fa219d4f4e3139 Mon Sep 17 00:00:00 2001 From: Orta Date: Tue, 31 Aug 2021 16:38:23 +0100 Subject: [PATCH 10/14] Allow undefined in Intl inputs to allow for ergonomic usage of exactOptionalPropertyTypes - see #45652 --- src/lib/es2018.intl.d.ts | 20 ++++---- src/lib/es2020.intl.d.ts | 26 +++++----- src/lib/es2021.intl.d.ts | 8 +-- src/lib/es5.d.ts | 60 +++++++++++----------- tests/cases/conformance/es2018/intlAPIs.ts | 8 +++ 5 files changed, 64 insertions(+), 58 deletions(-) create mode 100644 tests/cases/conformance/es2018/intlAPIs.ts diff --git a/src/lib/es2018.intl.d.ts b/src/lib/es2018.intl.d.ts index 4586a1dde2785..2c5cc1787a40b 100644 --- a/src/lib/es2018.intl.d.ts +++ b/src/lib/es2018.intl.d.ts @@ -5,13 +5,13 @@ declare namespace Intl { type PluralRuleType = "cardinal" | "ordinal"; interface PluralRulesOptions { - localeMatcher?: "lookup" | "best fit"; - type?: PluralRuleType; - minimumIntegerDigits?: number; - minimumFractionDigits?: number; - maximumFractionDigits?: number; - minimumSignificantDigits?: number; - maximumSignificantDigits?: number; + localeMatcher?: "lookup" | "best fit" | undefined; + type?: PluralRuleType | undefined; + minimumIntegerDigits?: number | undefined; + minimumFractionDigits?: number | undefined; + maximumFractionDigits?: number | undefined; + minimumSignificantDigits?: number | undefined; + maximumSignificantDigits?: number | undefined; } interface ResolvedPluralRulesOptions { @@ -33,10 +33,8 @@ declare namespace Intl { const PluralRules: { new (locales?: string | string[], options?: PluralRulesOptions): PluralRules; (locales?: string | string[], options?: PluralRulesOptions): PluralRules; - supportedLocalesOf( - locales: string | string[], - options?: PluralRulesOptions, - ): string[]; + + supportedLocalesOf(locales: string | string[], options?: { localeMatcher?: "lookup" | "best fit" }): string[]; }; interface NumberFormatPart { diff --git a/src/lib/es2020.intl.d.ts b/src/lib/es2020.intl.d.ts index 405eeaff8d48d..9c941e97477dc 100644 --- a/src/lib/es2020.intl.d.ts +++ b/src/lib/es2020.intl.d.ts @@ -198,11 +198,11 @@ declare namespace Intl { }; interface NumberFormatOptions { - compactDisplay?: "short" | "long"; - notation?: "standard" | "scientific" | "engineering" | "compact"; - signDisplay?: "auto" | "never" | "always"; - unit?: NumberFormatUnit; - unitDisplay?: "short" | "long" | "narrow"; + compactDisplay?: "short" | "long" | undefined; + notation?: "standard" | "scientific" | "engineering" | "compact" | undefined; + signDisplay?: "auto" | "never" | "always" | undefined; + unit?: NumberFormatUnit | undefined; + unitDisplay?: "short" | "long" | "narrow" | undefined; } interface ResolvedNumberFormatOptions { @@ -214,16 +214,16 @@ declare namespace Intl { } interface DateTimeFormatOptions { - calendar?: string; - dayPeriod?: "narrow" | "short" | "long"; - numberingSystem?: string; - hourCycle?: "h11" | "h12" | "h23" | "h24"; + calendar?: string | undefined; + dayPeriod?: "narrow" | "short" | "long" | undefined; + numberingSystem?: string | undefined; + hourCycle?: "h11" | "h12" | "h23" | "h24" | undefined; } interface DateTimeFormatOptions { - dateStyle?: "full" | "long" | "medium" | "short"; - timeStyle?: "full" | "long" | "medium" | "short"; - hourCycle?: "h11" | "h12" | "h23" | "h24"; + dateStyle?: "full" | "long" | "medium" | "short" | undefined; + timeStyle?: "full" | "long" | "medium" | "short" | undefined; + hourCycle?: "h11" | "h12" | "h23" | "h24" | undefined; } type LocaleHourCycleKey = "h12" | "h23" | "h11" | "h24"; @@ -345,7 +345,7 @@ declare namespace Intl { * * [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/supportedLocalesOf). */ - supportedLocalesOf(locales: BCP47LanguageTag | BCP47LanguageTag[], options: {localeMatcher: RelativeTimeFormatLocaleMatcher}): BCP47LanguageTag[]; + supportedLocalesOf(locales: BCP47LanguageTag | BCP47LanguageTag[], options?: {localeMatcher: RelativeTimeFormatLocaleMatcher}): BCP47LanguageTag[]; }; } diff --git a/src/lib/es2021.intl.d.ts b/src/lib/es2021.intl.d.ts index 74d0158d6f325..f1fde8b7ee4ec 100644 --- a/src/lib/es2021.intl.d.ts +++ b/src/lib/es2021.intl.d.ts @@ -1,9 +1,9 @@ declare namespace Intl { interface DateTimeFormatOptions { - dateStyle?: "full" | "long" | "medium" | "short"; - timeStyle?: "full" | "long" | "medium" | "short"; - dayPeriod?: "narrow" | "short" | "long"; - fractionalSecondDigits?: 0 | 1 | 2 | 3; + dateStyle?: "full" | "long" | "medium" | "short" | undefined; + timeStyle?: "full" | "long" | "medium" | "short" | undefined; + dayPeriod?: "narrow" | "short" | "long" | undefined; + fractionalSecondDigits?: 0 | 1 | 2 | 3 | undefined; } } \ No newline at end of file diff --git a/src/lib/es5.d.ts b/src/lib/es5.d.ts index f485a39996ee3..1d78da7dd6b20 100644 --- a/src/lib/es5.d.ts +++ b/src/lib/es5.d.ts @@ -4295,12 +4295,12 @@ declare var Float64Array: Float64ArrayConstructor; declare namespace Intl { interface CollatorOptions { - usage?: string; - localeMatcher?: string; - numeric?: boolean; - caseFirst?: string; - sensitivity?: string; - ignorePunctuation?: boolean; + usage?: string | undefined; + localeMatcher?: string | undefined; + numeric?: boolean | undefined; + caseFirst?: string | undefined; + sensitivity?: string | undefined; + ignorePunctuation?: boolean | undefined; } interface ResolvedCollatorOptions { @@ -4324,17 +4324,17 @@ declare namespace Intl { }; interface NumberFormatOptions { - localeMatcher?: string; - style?: string; - currency?: string; - currencyDisplay?: string; - currencySign?: string; - useGrouping?: boolean; - minimumIntegerDigits?: number; - minimumFractionDigits?: number; - maximumFractionDigits?: number; - minimumSignificantDigits?: number; - maximumSignificantDigits?: number; + localeMatcher?: string | undefined; + style?: string | undefined; + currency?: string | undefined; + currencyDisplay?: string | undefined; + currencySign?: string | undefined; + useGrouping?: boolean | undefined; + minimumIntegerDigits?: number | undefined; + minimumFractionDigits?: number | undefined; + maximumFractionDigits?: number | undefined; + minimumSignificantDigits?: number | undefined; + maximumSignificantDigits?: number | undefined; } interface ResolvedNumberFormatOptions { @@ -4362,19 +4362,19 @@ declare namespace Intl { }; interface DateTimeFormatOptions { - localeMatcher?: "best fit" | "lookup"; - weekday?: "long" | "short" | "narrow"; - era?: "long" | "short" | "narrow"; - year?: "numeric" | "2-digit"; - month?: "numeric" | "2-digit" | "long" | "short" | "narrow"; - day?: "numeric" | "2-digit"; - hour?: "numeric" | "2-digit"; - minute?: "numeric" | "2-digit"; - second?: "numeric" | "2-digit"; - timeZoneName?: "long" | "short"; - formatMatcher?: "best fit" | "basic"; - hour12?: boolean; - timeZone?: string; + localeMatcher?: "best fit" | "lookup" | undefined; + weekday?: "long" | "short" | "narrow" | undefined; + era?: "long" | "short" | "narrow" | undefined; + year?: "numeric" | "2-digit" | undefined; + month?: "numeric" | "2-digit" | "long" | "short" | "narrow" | undefined; + day?: "numeric" | "2-digit" | undefined; + hour?: "numeric" | "2-digit" | undefined; + minute?: "numeric" | "2-digit" | undefined; + second?: "numeric" | "2-digit" | undefined; + timeZoneName?: "long" | "short" | undefined; + formatMatcher?: "best fit" | "basic" | undefined; + hour12?: boolean | undefined; + timeZone?: string | undefined; } interface ResolvedDateTimeFormatOptions { diff --git a/tests/cases/conformance/es2018/intlAPIs.ts b/tests/cases/conformance/es2018/intlAPIs.ts new file mode 100644 index 0000000000000..957498f8c156f --- /dev/null +++ b/tests/cases/conformance/es2018/intlAPIs.ts @@ -0,0 +1,8 @@ +// @target: es5 +// @lib: es6,es2018 + +// Sample from +// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/PluralRules/supportedLocalesOf +const locales = ['ban', 'id-u-co-pinyin', 'de-ID']; +const options = { localeMatcher: 'lookup' } as const; +console.log(Intl.PluralRules.supportedLocalesOf(locales, options).join(', ')); \ No newline at end of file From fdbc99a7293934a78e0396000f43a2b3c2a1799a Mon Sep 17 00:00:00 2001 From: Orta Date: Tue, 31 Aug 2021 17:10:12 +0100 Subject: [PATCH 11/14] Adds some tests covering the APIs --- tests/baselines/reference/es2018IntlAPIs.js | 13 ++ .../reference/es2018IntlAPIs.symbols | 24 ++ .../baselines/reference/es2018IntlAPIs.types | 35 +++ tests/baselines/reference/es2020IntlAPIs.js | 75 +++++++ .../reference/es2020IntlAPIs.symbols | 148 +++++++++++++ .../baselines/reference/es2020IntlAPIs.types | 209 ++++++++++++++++++ .../es2018/{intlAPIs.ts => es2018IntlAPIs.ts} | 3 +- .../conformance/es2020/es2020IntlAPIs.ts | 45 ++++ 8 files changed, 550 insertions(+), 2 deletions(-) create mode 100644 tests/baselines/reference/es2018IntlAPIs.js create mode 100644 tests/baselines/reference/es2018IntlAPIs.symbols create mode 100644 tests/baselines/reference/es2018IntlAPIs.types create mode 100644 tests/baselines/reference/es2020IntlAPIs.js create mode 100644 tests/baselines/reference/es2020IntlAPIs.symbols create mode 100644 tests/baselines/reference/es2020IntlAPIs.types rename tests/cases/conformance/es2018/{intlAPIs.ts => es2018IntlAPIs.ts} (89%) create mode 100644 tests/cases/conformance/es2020/es2020IntlAPIs.ts diff --git a/tests/baselines/reference/es2018IntlAPIs.js b/tests/baselines/reference/es2018IntlAPIs.js new file mode 100644 index 0000000000000..4a723f773eb29 --- /dev/null +++ b/tests/baselines/reference/es2018IntlAPIs.js @@ -0,0 +1,13 @@ +//// [es2018IntlAPIs.ts] +// Sample from +// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/PluralRules/supportedLocalesOf +const locales = ['ban', 'id-u-co-pinyin', 'de-ID']; +const options = { localeMatcher: 'lookup' } as const; +console.log(Intl.PluralRules.supportedLocalesOf(locales, options).join(', ')); + +//// [es2018IntlAPIs.js] +// Sample from +// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/PluralRules/supportedLocalesOf +const locales = ['ban', 'id-u-co-pinyin', 'de-ID']; +const options = { localeMatcher: 'lookup' }; +console.log(Intl.PluralRules.supportedLocalesOf(locales, options).join(', ')); diff --git a/tests/baselines/reference/es2018IntlAPIs.symbols b/tests/baselines/reference/es2018IntlAPIs.symbols new file mode 100644 index 0000000000000..fc19095f4f827 --- /dev/null +++ b/tests/baselines/reference/es2018IntlAPIs.symbols @@ -0,0 +1,24 @@ +=== tests/cases/conformance/es2018/es2018IntlAPIs.ts === +// Sample from +// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/PluralRules/supportedLocalesOf +const locales = ['ban', 'id-u-co-pinyin', 'de-ID']; +>locales : Symbol(locales, Decl(es2018IntlAPIs.ts, 2, 5)) + +const options = { localeMatcher: 'lookup' } as const; +>options : Symbol(options, Decl(es2018IntlAPIs.ts, 3, 5)) +>localeMatcher : Symbol(localeMatcher, Decl(es2018IntlAPIs.ts, 3, 17)) + +console.log(Intl.PluralRules.supportedLocalesOf(locales, options).join(', ')); +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>Intl.PluralRules.supportedLocalesOf(locales, options).join : Symbol(Array.join, Decl(lib.es5.d.ts, --, --)) +>Intl.PluralRules.supportedLocalesOf : Symbol(supportedLocalesOf, Decl(lib.es2018.intl.d.ts, --, --)) +>Intl.PluralRules : Symbol(Intl.PluralRules, Decl(lib.es2018.intl.d.ts, --, --), Decl(lib.es2018.intl.d.ts, --, --)) +>Intl : Symbol(Intl, Decl(lib.es5.d.ts, --, --), Decl(lib.es2017.intl.d.ts, --, --), Decl(lib.es2018.intl.d.ts, --, --)) +>PluralRules : Symbol(Intl.PluralRules, Decl(lib.es2018.intl.d.ts, --, --), Decl(lib.es2018.intl.d.ts, --, --)) +>supportedLocalesOf : Symbol(supportedLocalesOf, Decl(lib.es2018.intl.d.ts, --, --)) +>locales : Symbol(locales, Decl(es2018IntlAPIs.ts, 2, 5)) +>options : Symbol(options, Decl(es2018IntlAPIs.ts, 3, 5)) +>join : Symbol(Array.join, Decl(lib.es5.d.ts, --, --)) + diff --git a/tests/baselines/reference/es2018IntlAPIs.types b/tests/baselines/reference/es2018IntlAPIs.types new file mode 100644 index 0000000000000..673beff6e94d3 --- /dev/null +++ b/tests/baselines/reference/es2018IntlAPIs.types @@ -0,0 +1,35 @@ +=== tests/cases/conformance/es2018/es2018IntlAPIs.ts === +// Sample from +// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/PluralRules/supportedLocalesOf +const locales = ['ban', 'id-u-co-pinyin', 'de-ID']; +>locales : string[] +>['ban', 'id-u-co-pinyin', 'de-ID'] : string[] +>'ban' : "ban" +>'id-u-co-pinyin' : "id-u-co-pinyin" +>'de-ID' : "de-ID" + +const options = { localeMatcher: 'lookup' } as const; +>options : { readonly localeMatcher: "lookup"; } +>{ localeMatcher: 'lookup' } as const : { readonly localeMatcher: "lookup"; } +>{ localeMatcher: 'lookup' } : { readonly localeMatcher: "lookup"; } +>localeMatcher : "lookup" +>'lookup' : "lookup" + +console.log(Intl.PluralRules.supportedLocalesOf(locales, options).join(', ')); +>console.log(Intl.PluralRules.supportedLocalesOf(locales, options).join(', ')) : void +>console.log : (...data: any[]) => void +>console : Console +>log : (...data: any[]) => void +>Intl.PluralRules.supportedLocalesOf(locales, options).join(', ') : string +>Intl.PluralRules.supportedLocalesOf(locales, options).join : (separator?: string) => string +>Intl.PluralRules.supportedLocalesOf(locales, options) : string[] +>Intl.PluralRules.supportedLocalesOf : (locales: string | string[], options?: { localeMatcher?: "lookup" | "best fit"; }) => string[] +>Intl.PluralRules : { (locales?: string | string[], options?: Intl.PluralRulesOptions): Intl.PluralRules; new (locales?: string | string[], options?: Intl.PluralRulesOptions): Intl.PluralRules; supportedLocalesOf(locales: string | string[], options?: { localeMatcher?: "lookup" | "best fit"; }): string[]; } +>Intl : typeof Intl +>PluralRules : { (locales?: string | string[], options?: Intl.PluralRulesOptions): Intl.PluralRules; new (locales?: string | string[], options?: Intl.PluralRulesOptions): Intl.PluralRules; supportedLocalesOf(locales: string | string[], options?: { localeMatcher?: "lookup" | "best fit"; }): string[]; } +>supportedLocalesOf : (locales: string | string[], options?: { localeMatcher?: "lookup" | "best fit"; }) => string[] +>locales : string[] +>options : { readonly localeMatcher: "lookup"; } +>join : (separator?: string) => string +>', ' : ", " + diff --git a/tests/baselines/reference/es2020IntlAPIs.js b/tests/baselines/reference/es2020IntlAPIs.js new file mode 100644 index 0000000000000..8136ff27ee070 --- /dev/null +++ b/tests/baselines/reference/es2020IntlAPIs.js @@ -0,0 +1,75 @@ +//// [es2020IntlAPIs.ts] +// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl#Locale_identification_and_negotiation +const count = 26254.39; +const date = new Date("2012-05-24"); + +function log(locale: string) { + console.log( + `${new Intl.DateTimeFormat(locale).format(date)} ${new Intl.NumberFormat(locale).format(count)}` + ); +} + +log("en-US"); +// expected output: 5/24/2012 26,254.39 + +log("de-DE"); +// expected output: 24.5.2012 26.254,39 + +// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat +const rtf1 = new Intl.RelativeTimeFormat('en', { style: 'narrow' }); + +console.log(rtf1.format(3, 'quarter')); +//expected output: "in 3 qtrs." + +console.log(rtf1.format(-1, 'day')); +//expected output: "1 day ago" + +const rtf2 = new Intl.RelativeTimeFormat('es', { numeric: 'auto' }); + +console.log(rtf2.format(2, 'day')); +//expected output: "pasado mañana" + +// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames +const regionNamesInEnglish = new Intl.DisplayNames(['en'], { type: 'region' }); +const regionNamesInTraditionalChinese = new Intl.DisplayNames(['zh-Hant'], { type: 'region' }); + +console.log(regionNamesInEnglish.of('US')); +// expected output: "United States" + +console.log(regionNamesInTraditionalChinese.of('US')); +// expected output: "美國" + +const locales1 = ['ban', 'id-u-co-pinyin', 'de-ID']; +const options1 = { localeMatcher: 'lookup' } as const; +console.log(Intl.DisplayNames.supportedLocalesOf(locales1, options1).join(', ')); + +//// [es2020IntlAPIs.js] +// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl#Locale_identification_and_negotiation +const count = 26254.39; +const date = new Date("2012-05-24"); +function log(locale) { + console.log(`${new Intl.DateTimeFormat(locale).format(date)} ${new Intl.NumberFormat(locale).format(count)}`); +} +log("en-US"); +// expected output: 5/24/2012 26,254.39 +log("de-DE"); +// expected output: 24.5.2012 26.254,39 +// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat +const rtf1 = new Intl.RelativeTimeFormat('en', { style: 'narrow' }); +console.log(rtf1.format(3, 'quarter')); +//expected output: "in 3 qtrs." +console.log(rtf1.format(-1, 'day')); +//expected output: "1 day ago" +const rtf2 = new Intl.RelativeTimeFormat('es', { numeric: 'auto' }); +console.log(rtf2.format(2, 'day')); +//expected output: "pasado mañana" +// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames +const regionNamesInEnglish = new Intl.DisplayNames(['en'], { type: 'region' }); +const regionNamesInTraditionalChinese = new Intl.DisplayNames(['zh-Hant'], { type: 'region' }); +console.log(regionNamesInEnglish.of('US')); +// expected output: "United States" +console.log(regionNamesInTraditionalChinese.of('US')); +// expected output: "美國" +const locales1 = ['ban', 'id-u-co-pinyin', 'de-ID']; +const options1 = { localeMatcher: 'lookup' }; +console.log(Intl.DisplayNames.supportedLocalesOf(locales1, options1).join(', ')); diff --git a/tests/baselines/reference/es2020IntlAPIs.symbols b/tests/baselines/reference/es2020IntlAPIs.symbols new file mode 100644 index 0000000000000..afb7113c1524e --- /dev/null +++ b/tests/baselines/reference/es2020IntlAPIs.symbols @@ -0,0 +1,148 @@ +=== tests/cases/conformance/es2020/es2020IntlAPIs.ts === +// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl#Locale_identification_and_negotiation +const count = 26254.39; +>count : Symbol(count, Decl(es2020IntlAPIs.ts, 1, 5)) + +const date = new Date("2012-05-24"); +>date : Symbol(date, Decl(es2020IntlAPIs.ts, 2, 5)) +>Date : Symbol(Date, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.scripthost.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --)) + +function log(locale: string) { +>log : Symbol(log, Decl(es2020IntlAPIs.ts, 2, 36)) +>locale : Symbol(locale, Decl(es2020IntlAPIs.ts, 4, 13)) + + console.log( +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) + + `${new Intl.DateTimeFormat(locale).format(date)} ${new Intl.NumberFormat(locale).format(count)}` +>new Intl.DateTimeFormat(locale).format : Symbol(Intl.DateTimeFormat.format, Decl(lib.es5.d.ts, --, --)) +>Intl.DateTimeFormat : Symbol(Intl.DateTimeFormat, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2017.intl.d.ts, --, --)) +>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, --, --)) +>DateTimeFormat : Symbol(Intl.DateTimeFormat, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2017.intl.d.ts, --, --)) +>locale : Symbol(locale, Decl(es2020IntlAPIs.ts, 4, 13)) +>format : Symbol(Intl.DateTimeFormat.format, Decl(lib.es5.d.ts, --, --)) +>date : Symbol(date, Decl(es2020IntlAPIs.ts, 2, 5)) +>new Intl.NumberFormat(locale).format : Symbol(Intl.NumberFormat.format, Decl(lib.es5.d.ts, --, --), Decl(lib.es2020.bigint.d.ts, --, --)) +>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, --, --)) +>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, --, --)) +>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, --, --)) +>locale : Symbol(locale, Decl(es2020IntlAPIs.ts, 4, 13)) +>format : Symbol(Intl.NumberFormat.format, Decl(lib.es5.d.ts, --, --), Decl(lib.es2020.bigint.d.ts, --, --)) +>count : Symbol(count, Decl(es2020IntlAPIs.ts, 1, 5)) + + ); +} + +log("en-US"); +>log : Symbol(log, Decl(es2020IntlAPIs.ts, 2, 36)) + +// expected output: 5/24/2012 26,254.39 + +log("de-DE"); +>log : Symbol(log, Decl(es2020IntlAPIs.ts, 2, 36)) + +// expected output: 24.5.2012 26.254,39 + +// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat +const rtf1 = new Intl.RelativeTimeFormat('en', { style: 'narrow' }); +>rtf1 : Symbol(rtf1, Decl(es2020IntlAPIs.ts, 17, 5)) +>Intl.RelativeTimeFormat : Symbol(Intl.RelativeTimeFormat, Decl(lib.es2020.intl.d.ts, --, --), Decl(lib.es2020.intl.d.ts, --, --)) +>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, --, --)) +>RelativeTimeFormat : Symbol(Intl.RelativeTimeFormat, Decl(lib.es2020.intl.d.ts, --, --), Decl(lib.es2020.intl.d.ts, --, --)) +>style : Symbol(style, Decl(es2020IntlAPIs.ts, 17, 48)) + +console.log(rtf1.format(3, 'quarter')); +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>rtf1.format : Symbol(Intl.RelativeTimeFormat.format, Decl(lib.es2020.intl.d.ts, --, --)) +>rtf1 : Symbol(rtf1, Decl(es2020IntlAPIs.ts, 17, 5)) +>format : Symbol(Intl.RelativeTimeFormat.format, Decl(lib.es2020.intl.d.ts, --, --)) + +//expected output: "in 3 qtrs." + +console.log(rtf1.format(-1, 'day')); +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>rtf1.format : Symbol(Intl.RelativeTimeFormat.format, Decl(lib.es2020.intl.d.ts, --, --)) +>rtf1 : Symbol(rtf1, Decl(es2020IntlAPIs.ts, 17, 5)) +>format : Symbol(Intl.RelativeTimeFormat.format, Decl(lib.es2020.intl.d.ts, --, --)) + +//expected output: "1 day ago" + +const rtf2 = new Intl.RelativeTimeFormat('es', { numeric: 'auto' }); +>rtf2 : Symbol(rtf2, Decl(es2020IntlAPIs.ts, 25, 5)) +>Intl.RelativeTimeFormat : Symbol(Intl.RelativeTimeFormat, Decl(lib.es2020.intl.d.ts, --, --), Decl(lib.es2020.intl.d.ts, --, --)) +>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, --, --)) +>RelativeTimeFormat : Symbol(Intl.RelativeTimeFormat, Decl(lib.es2020.intl.d.ts, --, --), Decl(lib.es2020.intl.d.ts, --, --)) +>numeric : Symbol(numeric, Decl(es2020IntlAPIs.ts, 25, 48)) + +console.log(rtf2.format(2, 'day')); +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>rtf2.format : Symbol(Intl.RelativeTimeFormat.format, Decl(lib.es2020.intl.d.ts, --, --)) +>rtf2 : Symbol(rtf2, Decl(es2020IntlAPIs.ts, 25, 5)) +>format : Symbol(Intl.RelativeTimeFormat.format, Decl(lib.es2020.intl.d.ts, --, --)) + +//expected output: "pasado mañana" + +// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames +const regionNamesInEnglish = new Intl.DisplayNames(['en'], { type: 'region' }); +>regionNamesInEnglish : Symbol(regionNamesInEnglish, Decl(es2020IntlAPIs.ts, 31, 5)) +>Intl.DisplayNames : Symbol(Intl.DisplayNames, Decl(lib.es2020.intl.d.ts, --, --), Decl(lib.es2020.intl.d.ts, --, --)) +>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, --, --)) +>DisplayNames : Symbol(Intl.DisplayNames, Decl(lib.es2020.intl.d.ts, --, --), Decl(lib.es2020.intl.d.ts, --, --)) +>type : Symbol(type, Decl(es2020IntlAPIs.ts, 31, 60)) + +const regionNamesInTraditionalChinese = new Intl.DisplayNames(['zh-Hant'], { type: 'region' }); +>regionNamesInTraditionalChinese : Symbol(regionNamesInTraditionalChinese, Decl(es2020IntlAPIs.ts, 32, 5)) +>Intl.DisplayNames : Symbol(Intl.DisplayNames, Decl(lib.es2020.intl.d.ts, --, --), Decl(lib.es2020.intl.d.ts, --, --)) +>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, --, --)) +>DisplayNames : Symbol(Intl.DisplayNames, Decl(lib.es2020.intl.d.ts, --, --), Decl(lib.es2020.intl.d.ts, --, --)) +>type : Symbol(type, Decl(es2020IntlAPIs.ts, 32, 76)) + +console.log(regionNamesInEnglish.of('US')); +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>regionNamesInEnglish.of : Symbol(Intl.DisplayNames.of, Decl(lib.es2020.intl.d.ts, --, --)) +>regionNamesInEnglish : Symbol(regionNamesInEnglish, Decl(es2020IntlAPIs.ts, 31, 5)) +>of : Symbol(Intl.DisplayNames.of, Decl(lib.es2020.intl.d.ts, --, --)) + +// expected output: "United States" + +console.log(regionNamesInTraditionalChinese.of('US')); +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>regionNamesInTraditionalChinese.of : Symbol(Intl.DisplayNames.of, Decl(lib.es2020.intl.d.ts, --, --)) +>regionNamesInTraditionalChinese : Symbol(regionNamesInTraditionalChinese, Decl(es2020IntlAPIs.ts, 32, 5)) +>of : Symbol(Intl.DisplayNames.of, Decl(lib.es2020.intl.d.ts, --, --)) + +// expected output: "美國" + +const locales1 = ['ban', 'id-u-co-pinyin', 'de-ID']; +>locales1 : Symbol(locales1, Decl(es2020IntlAPIs.ts, 40, 5)) + +const options1 = { localeMatcher: 'lookup' } as const; +>options1 : Symbol(options1, Decl(es2020IntlAPIs.ts, 41, 5)) +>localeMatcher : Symbol(localeMatcher, Decl(es2020IntlAPIs.ts, 41, 18)) + +console.log(Intl.DisplayNames.supportedLocalesOf(locales1, options1).join(', ')); +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>Intl.DisplayNames.supportedLocalesOf(locales1, options1).join : Symbol(Array.join, Decl(lib.es5.d.ts, --, --)) +>Intl.DisplayNames.supportedLocalesOf : Symbol(supportedLocalesOf, Decl(lib.es2020.intl.d.ts, --, --)) +>Intl.DisplayNames : Symbol(Intl.DisplayNames, Decl(lib.es2020.intl.d.ts, --, --), Decl(lib.es2020.intl.d.ts, --, --)) +>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, --, --)) +>DisplayNames : Symbol(Intl.DisplayNames, Decl(lib.es2020.intl.d.ts, --, --), Decl(lib.es2020.intl.d.ts, --, --)) +>supportedLocalesOf : Symbol(supportedLocalesOf, Decl(lib.es2020.intl.d.ts, --, --)) +>locales1 : Symbol(locales1, Decl(es2020IntlAPIs.ts, 40, 5)) +>options1 : Symbol(options1, Decl(es2020IntlAPIs.ts, 41, 5)) +>join : Symbol(Array.join, Decl(lib.es5.d.ts, --, --)) + diff --git a/tests/baselines/reference/es2020IntlAPIs.types b/tests/baselines/reference/es2020IntlAPIs.types new file mode 100644 index 0000000000000..f1315c55e9c9f --- /dev/null +++ b/tests/baselines/reference/es2020IntlAPIs.types @@ -0,0 +1,209 @@ +=== tests/cases/conformance/es2020/es2020IntlAPIs.ts === +// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl#Locale_identification_and_negotiation +const count = 26254.39; +>count : 26254.39 +>26254.39 : 26254.39 + +const date = new Date("2012-05-24"); +>date : Date +>new Date("2012-05-24") : Date +>Date : DateConstructor +>"2012-05-24" : "2012-05-24" + +function log(locale: string) { +>log : (locale: string) => void +>locale : string + + console.log( +>console.log( `${new Intl.DateTimeFormat(locale).format(date)} ${new Intl.NumberFormat(locale).format(count)}` ) : void +>console.log : (...data: any[]) => void +>console : Console +>log : (...data: any[]) => void + + `${new Intl.DateTimeFormat(locale).format(date)} ${new Intl.NumberFormat(locale).format(count)}` +>`${new Intl.DateTimeFormat(locale).format(date)} ${new Intl.NumberFormat(locale).format(count)}` : string +>new Intl.DateTimeFormat(locale).format(date) : string +>new Intl.DateTimeFormat(locale).format : (date?: number | Date) => string +>new Intl.DateTimeFormat(locale) : Intl.DateTimeFormat +>Intl.DateTimeFormat : { (locales?: string | string[], options?: Intl.DateTimeFormatOptions): Intl.DateTimeFormat; new (locales?: string | string[], options?: Intl.DateTimeFormatOptions): Intl.DateTimeFormat; supportedLocalesOf(locales: string | string[], options?: Intl.DateTimeFormatOptions): string[]; } +>Intl : typeof Intl +>DateTimeFormat : { (locales?: string | string[], options?: Intl.DateTimeFormatOptions): Intl.DateTimeFormat; new (locales?: string | string[], options?: Intl.DateTimeFormatOptions): Intl.DateTimeFormat; supportedLocalesOf(locales: string | string[], options?: Intl.DateTimeFormatOptions): string[]; } +>locale : string +>format : (date?: number | Date) => string +>date : Date +>new Intl.NumberFormat(locale).format(count) : string +>new Intl.NumberFormat(locale).format : { (value: number): string; (value: number | bigint): string; } +>new Intl.NumberFormat(locale) : Intl.NumberFormat +>Intl.NumberFormat : { (locales?: string | string[], options?: Intl.NumberFormatOptions): Intl.NumberFormat; new (locales?: string | string[], options?: Intl.NumberFormatOptions): Intl.NumberFormat; supportedLocalesOf(locales: string | string[], options?: Intl.NumberFormatOptions): string[]; } +>Intl : typeof Intl +>NumberFormat : { (locales?: string | string[], options?: Intl.NumberFormatOptions): Intl.NumberFormat; new (locales?: string | string[], options?: Intl.NumberFormatOptions): Intl.NumberFormat; supportedLocalesOf(locales: string | string[], options?: Intl.NumberFormatOptions): string[]; } +>locale : string +>format : { (value: number): string; (value: number | bigint): string; } +>count : 26254.39 + + ); +} + +log("en-US"); +>log("en-US") : void +>log : (locale: string) => void +>"en-US" : "en-US" + +// expected output: 5/24/2012 26,254.39 + +log("de-DE"); +>log("de-DE") : void +>log : (locale: string) => void +>"de-DE" : "de-DE" + +// expected output: 24.5.2012 26.254,39 + +// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat +const rtf1 = new Intl.RelativeTimeFormat('en', { style: 'narrow' }); +>rtf1 : Intl.RelativeTimeFormat +>new Intl.RelativeTimeFormat('en', { style: 'narrow' }) : Intl.RelativeTimeFormat +>Intl.RelativeTimeFormat : { new (locales?: string | string[], options?: Intl.RelativeTimeFormatOptions): Intl.RelativeTimeFormat; supportedLocalesOf(locales?: string | string[], options?: Intl.RelativeTimeFormatOptions): string[]; } +>Intl : typeof Intl +>RelativeTimeFormat : { new (locales?: string | string[], options?: Intl.RelativeTimeFormatOptions): Intl.RelativeTimeFormat; supportedLocalesOf(locales?: string | string[], options?: Intl.RelativeTimeFormatOptions): string[]; } +>'en' : "en" +>{ style: 'narrow' } : { style: "narrow"; } +>style : "narrow" +>'narrow' : "narrow" + +console.log(rtf1.format(3, 'quarter')); +>console.log(rtf1.format(3, 'quarter')) : void +>console.log : (...data: any[]) => void +>console : Console +>log : (...data: any[]) => void +>rtf1.format(3, 'quarter') : string +>rtf1.format : (value: number, unit: Intl.RelativeTimeFormatUnit) => string +>rtf1 : Intl.RelativeTimeFormat +>format : (value: number, unit: Intl.RelativeTimeFormatUnit) => string +>3 : 3 +>'quarter' : "quarter" + +//expected output: "in 3 qtrs." + +console.log(rtf1.format(-1, 'day')); +>console.log(rtf1.format(-1, 'day')) : void +>console.log : (...data: any[]) => void +>console : Console +>log : (...data: any[]) => void +>rtf1.format(-1, 'day') : string +>rtf1.format : (value: number, unit: Intl.RelativeTimeFormatUnit) => string +>rtf1 : Intl.RelativeTimeFormat +>format : (value: number, unit: Intl.RelativeTimeFormatUnit) => string +>-1 : -1 +>1 : 1 +>'day' : "day" + +//expected output: "1 day ago" + +const rtf2 = new Intl.RelativeTimeFormat('es', { numeric: 'auto' }); +>rtf2 : Intl.RelativeTimeFormat +>new Intl.RelativeTimeFormat('es', { numeric: 'auto' }) : Intl.RelativeTimeFormat +>Intl.RelativeTimeFormat : { new (locales?: string | string[], options?: Intl.RelativeTimeFormatOptions): Intl.RelativeTimeFormat; supportedLocalesOf(locales?: string | string[], options?: Intl.RelativeTimeFormatOptions): string[]; } +>Intl : typeof Intl +>RelativeTimeFormat : { new (locales?: string | string[], options?: Intl.RelativeTimeFormatOptions): Intl.RelativeTimeFormat; supportedLocalesOf(locales?: string | string[], options?: Intl.RelativeTimeFormatOptions): string[]; } +>'es' : "es" +>{ numeric: 'auto' } : { numeric: "auto"; } +>numeric : "auto" +>'auto' : "auto" + +console.log(rtf2.format(2, 'day')); +>console.log(rtf2.format(2, 'day')) : void +>console.log : (...data: any[]) => void +>console : Console +>log : (...data: any[]) => void +>rtf2.format(2, 'day') : string +>rtf2.format : (value: number, unit: Intl.RelativeTimeFormatUnit) => string +>rtf2 : Intl.RelativeTimeFormat +>format : (value: number, unit: Intl.RelativeTimeFormatUnit) => string +>2 : 2 +>'day' : "day" + +//expected output: "pasado mañana" + +// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames +const regionNamesInEnglish = new Intl.DisplayNames(['en'], { type: 'region' }); +>regionNamesInEnglish : Intl.DisplayNames +>new Intl.DisplayNames(['en'], { type: 'region' }) : Intl.DisplayNames +>Intl.DisplayNames : { new (locales?: string | string[], options?: Partial): Intl.DisplayNames; prototype: Intl.DisplayNames; supportedLocalesOf(locales: string | string[], options?: { localeMatcher: Intl.RelativeTimeFormatLocaleMatcher; }): string[]; } +>Intl : typeof Intl +>DisplayNames : { new (locales?: string | string[], options?: Partial): Intl.DisplayNames; prototype: Intl.DisplayNames; supportedLocalesOf(locales: string | string[], options?: { localeMatcher: Intl.RelativeTimeFormatLocaleMatcher; }): string[]; } +>['en'] : string[] +>'en' : "en" +>{ type: 'region' } : { type: "region"; } +>type : "region" +>'region' : "region" + +const regionNamesInTraditionalChinese = new Intl.DisplayNames(['zh-Hant'], { type: 'region' }); +>regionNamesInTraditionalChinese : Intl.DisplayNames +>new Intl.DisplayNames(['zh-Hant'], { type: 'region' }) : Intl.DisplayNames +>Intl.DisplayNames : { new (locales?: string | string[], options?: Partial): Intl.DisplayNames; prototype: Intl.DisplayNames; supportedLocalesOf(locales: string | string[], options?: { localeMatcher: Intl.RelativeTimeFormatLocaleMatcher; }): string[]; } +>Intl : typeof Intl +>DisplayNames : { new (locales?: string | string[], options?: Partial): Intl.DisplayNames; prototype: Intl.DisplayNames; supportedLocalesOf(locales: string | string[], options?: { localeMatcher: Intl.RelativeTimeFormatLocaleMatcher; }): string[]; } +>['zh-Hant'] : string[] +>'zh-Hant' : "zh-Hant" +>{ type: 'region' } : { type: "region"; } +>type : "region" +>'region' : "region" + +console.log(regionNamesInEnglish.of('US')); +>console.log(regionNamesInEnglish.of('US')) : void +>console.log : (...data: any[]) => void +>console : Console +>log : (...data: any[]) => void +>regionNamesInEnglish.of('US') : string +>regionNamesInEnglish.of : (code: string) => string +>regionNamesInEnglish : Intl.DisplayNames +>of : (code: string) => string +>'US' : "US" + +// expected output: "United States" + +console.log(regionNamesInTraditionalChinese.of('US')); +>console.log(regionNamesInTraditionalChinese.of('US')) : void +>console.log : (...data: any[]) => void +>console : Console +>log : (...data: any[]) => void +>regionNamesInTraditionalChinese.of('US') : string +>regionNamesInTraditionalChinese.of : (code: string) => string +>regionNamesInTraditionalChinese : Intl.DisplayNames +>of : (code: string) => string +>'US' : "US" + +// expected output: "美國" + +const locales1 = ['ban', 'id-u-co-pinyin', 'de-ID']; +>locales1 : string[] +>['ban', 'id-u-co-pinyin', 'de-ID'] : string[] +>'ban' : "ban" +>'id-u-co-pinyin' : "id-u-co-pinyin" +>'de-ID' : "de-ID" + +const options1 = { localeMatcher: 'lookup' } as const; +>options1 : { readonly localeMatcher: "lookup"; } +>{ localeMatcher: 'lookup' } as const : { readonly localeMatcher: "lookup"; } +>{ localeMatcher: 'lookup' } : { readonly localeMatcher: "lookup"; } +>localeMatcher : "lookup" +>'lookup' : "lookup" + +console.log(Intl.DisplayNames.supportedLocalesOf(locales1, options1).join(', ')); +>console.log(Intl.DisplayNames.supportedLocalesOf(locales1, options1).join(', ')) : void +>console.log : (...data: any[]) => void +>console : Console +>log : (...data: any[]) => void +>Intl.DisplayNames.supportedLocalesOf(locales1, options1).join(', ') : string +>Intl.DisplayNames.supportedLocalesOf(locales1, options1).join : (separator?: string) => string +>Intl.DisplayNames.supportedLocalesOf(locales1, options1) : string[] +>Intl.DisplayNames.supportedLocalesOf : (locales: string | string[], options?: { localeMatcher: Intl.RelativeTimeFormatLocaleMatcher; }) => string[] +>Intl.DisplayNames : { new (locales?: string | string[], options?: Partial): Intl.DisplayNames; prototype: Intl.DisplayNames; supportedLocalesOf(locales: string | string[], options?: { localeMatcher: Intl.RelativeTimeFormatLocaleMatcher; }): string[]; } +>Intl : typeof Intl +>DisplayNames : { new (locales?: string | string[], options?: Partial): Intl.DisplayNames; prototype: Intl.DisplayNames; supportedLocalesOf(locales: string | string[], options?: { localeMatcher: Intl.RelativeTimeFormatLocaleMatcher; }): string[]; } +>supportedLocalesOf : (locales: string | string[], options?: { localeMatcher: Intl.RelativeTimeFormatLocaleMatcher; }) => string[] +>locales1 : string[] +>options1 : { readonly localeMatcher: "lookup"; } +>join : (separator?: string) => string +>', ' : ", " + diff --git a/tests/cases/conformance/es2018/intlAPIs.ts b/tests/cases/conformance/es2018/es2018IntlAPIs.ts similarity index 89% rename from tests/cases/conformance/es2018/intlAPIs.ts rename to tests/cases/conformance/es2018/es2018IntlAPIs.ts index 957498f8c156f..c1f6739202d72 100644 --- a/tests/cases/conformance/es2018/intlAPIs.ts +++ b/tests/cases/conformance/es2018/es2018IntlAPIs.ts @@ -1,5 +1,4 @@ -// @target: es5 -// @lib: es6,es2018 +// @target: es2018 // Sample from // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/PluralRules/supportedLocalesOf diff --git a/tests/cases/conformance/es2020/es2020IntlAPIs.ts b/tests/cases/conformance/es2020/es2020IntlAPIs.ts new file mode 100644 index 0000000000000..464ecc01ecf6a --- /dev/null +++ b/tests/cases/conformance/es2020/es2020IntlAPIs.ts @@ -0,0 +1,45 @@ +// @target: es2020 + +// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl#Locale_identification_and_negotiation +const count = 26254.39; +const date = new Date("2012-05-24"); + +function log(locale: string) { + console.log( + `${new Intl.DateTimeFormat(locale).format(date)} ${new Intl.NumberFormat(locale).format(count)}` + ); +} + +log("en-US"); +// expected output: 5/24/2012 26,254.39 + +log("de-DE"); +// expected output: 24.5.2012 26.254,39 + +// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat +const rtf1 = new Intl.RelativeTimeFormat('en', { style: 'narrow' }); + +console.log(rtf1.format(3, 'quarter')); +//expected output: "in 3 qtrs." + +console.log(rtf1.format(-1, 'day')); +//expected output: "1 day ago" + +const rtf2 = new Intl.RelativeTimeFormat('es', { numeric: 'auto' }); + +console.log(rtf2.format(2, 'day')); +//expected output: "pasado mañana" + +// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames +const regionNamesInEnglish = new Intl.DisplayNames(['en'], { type: 'region' }); +const regionNamesInTraditionalChinese = new Intl.DisplayNames(['zh-Hant'], { type: 'region' }); + +console.log(regionNamesInEnglish.of('US')); +// expected output: "United States" + +console.log(regionNamesInTraditionalChinese.of('US')); +// expected output: "美國" + +const locales1 = ['ban', 'id-u-co-pinyin', 'de-ID']; +const options1 = { localeMatcher: 'lookup' } as const; +console.log(Intl.DisplayNames.supportedLocalesOf(locales1, options1).join(', ')); \ No newline at end of file From 01a6f7823fd6f3fabd4ef27ef761d8a74dabd424 Mon Sep 17 00:00:00 2001 From: Orta Therox Date: Mon, 6 Sep 2021 15:48:39 +0000 Subject: [PATCH 12/14] Apply suggestions from code review Co-authored-by: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> --- src/lib/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/lib/README.md b/src/lib/README.md index 136225dde63a6..afd1be3f078f0 100644 --- a/src/lib/README.md +++ b/src/lib/README.md @@ -5,7 +5,7 @@ The files within this directory are copied and deployed with TypeScript as the s There are three main domains of APIs in `src/lib`: - **ECMAScript language features** - e.g. JavaScript APIs like functions on Array etc which are documented in [ECMA-262](https://tc39.es/ecma262/) - - **DOM APIs** - e.g. APIs which are available in Web Browsers + - **DOM APIs** - e.g. APIs which are available in web browsers - **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/) Finished proposals, anything in here can safely be added according to the years the proposal was added: @@ -15,9 +15,9 @@ Finished proposals, anything in here can safely be added according to the years ## How do we figure out when to add something? -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 usually means the proposal is at stage 3 or later. +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. -For the DOM APIs, which are a bit more free-form we have ask that APIs are available (un-prefixed/flagged) in at least 2 browser _engines_ (e.g. not just 2 chromium browsers.) +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.) ## Generated files From aecec76c5934f2f52dda2e0ae6071ff49909b4cc Mon Sep 17 00:00:00 2001 From: Orta Date: Mon, 6 Sep 2021 17:26:05 +0100 Subject: [PATCH 13/14] Handle PR feedback --- src/lib/README.md | 12 ++++++------ src/lib/es2018.intl.d.ts | 2 +- src/lib/es2020.intl.d.ts | 7 ++++--- src/lib/es2021.intl.d.ts | 6 ++++++ 4 files changed, 17 insertions(+), 10 deletions(-) diff --git a/src/lib/README.md b/src/lib/README.md index 136225dde63a6..e3bca6b0e2e51 100644 --- a/src/lib/README.md +++ b/src/lib/README.md @@ -8,19 +8,19 @@ There are three main domains of APIs in `src/lib`: - **DOM APIs** - e.g. APIs which are available in Web Browsers - **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/) -Finished proposals, anything in here can safely be added according to the years the proposal was added: - - - [JavaScript](https://github.com/tc39/proposals/blob/master/finished-proposals.md) - - [Intl](https://github.com/tc39/proposals/blob/master/ecma402/finished-proposals.md) - ## How do we figure out when to add something? 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 usually means the proposal is at stage 3 or later. +You can find the source of truth for modern language features and Intl APIs in these completed proposal lists: + + - [JavaScript](https://github.com/tc39/proposals/blob/master/finished-proposals.md) + - [Intl](https://github.com/tc39/proposals/blob/master/ecma402/finished-proposals.md) + For the DOM APIs, which are a bit more free-form we have ask that APIs are available (un-prefixed/flagged) in at least 2 browser _engines_ (e.g. not just 2 chromium browsers.) ## Generated files The DOM files ending in `.generated.d.ts` aren't meant to be edited by hand. -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). +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). diff --git a/src/lib/es2018.intl.d.ts b/src/lib/es2018.intl.d.ts index 2c5cc1787a40b..7f814195cfcd8 100644 --- a/src/lib/es2018.intl.d.ts +++ b/src/lib/es2018.intl.d.ts @@ -38,7 +38,7 @@ declare namespace Intl { }; interface NumberFormatPart { - type: "compact" | "currency" | "decimal" | "exponentInteger" | "exponentMinusSign" | "exponentSeparator" | "fraction" | "group" | "infinity" | "integer" | "literal" | "minusSign" | "nan" | "plusSign" | "percentSign" | "unit" | "unknown"; + type: "literal" | "nan" | "infinity" | "percent" | "integer" | "group" | "decimal" | "fraction" | "plusSign" | "minusSign" | "percentSign" | "currency" | "code" | "symbol" | "name"; value: string; } diff --git a/src/lib/es2020.intl.d.ts b/src/lib/es2020.intl.d.ts index 9c941e97477dc..edb886980ec4a 100644 --- a/src/lib/es2020.intl.d.ts +++ b/src/lib/es2020.intl.d.ts @@ -197,6 +197,10 @@ declare namespace Intl { ): UnicodeBCP47LocaleIdentifier[]; }; + interface NumberFormatPart { + type: "compact" | "currency" | "decimal" | "exponentInteger" | "exponentMinusSign" | "exponentSeparator" | "fraction" | "group" | "infinity" | "integer" | "literal" | "minusSign" | "nan" | "plusSign" | "percentSign" | "unit" | "unknown"; + } + interface NumberFormatOptions { compactDisplay?: "short" | "long" | undefined; notation?: "standard" | "scientific" | "engineering" | "compact" | undefined; @@ -217,10 +221,7 @@ declare namespace Intl { calendar?: string | undefined; dayPeriod?: "narrow" | "short" | "long" | undefined; numberingSystem?: string | undefined; - hourCycle?: "h11" | "h12" | "h23" | "h24" | undefined; - } - interface DateTimeFormatOptions { dateStyle?: "full" | "long" | "medium" | "short" | undefined; timeStyle?: "full" | "long" | "medium" | "short" | undefined; hourCycle?: "h11" | "h12" | "h23" | "h24" | undefined; diff --git a/src/lib/es2021.intl.d.ts b/src/lib/es2021.intl.d.ts index f1fde8b7ee4ec..d0652af1edbb9 100644 --- a/src/lib/es2021.intl.d.ts +++ b/src/lib/es2021.intl.d.ts @@ -1,9 +1,15 @@ declare namespace Intl { interface DateTimeFormatOptions { + formatMatcher?: "basic" | "best fit" | "best fit"; dateStyle?: "full" | "long" | "medium" | "short" | undefined; timeStyle?: "full" | "long" | "medium" | "short" | undefined; dayPeriod?: "narrow" | "short" | "long" | undefined; fractionalSecondDigits?: 0 | 1 | 2 | 3 | undefined; } + + interface NumberFormat { + formatRange(startDate: number | bigint, endDate: number | bigint): string; + formatRangeToParts(startDate: number | bigint, endDate: number | bigint): NumberFormatPart[]; + } } \ No newline at end of file From e79c4cd83dca9a6e7777ceb3b63a97c3f4f1cfe6 Mon Sep 17 00:00:00 2001 From: Orta Date: Tue, 7 Sep 2021 10:59:45 +0100 Subject: [PATCH 14/14] More review improvements --- src/lib/es2018.intl.d.ts | 3 ++- src/lib/es2020.intl.d.ts | 3 ++- src/lib/es2021.intl.d.ts | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/lib/es2018.intl.d.ts b/src/lib/es2018.intl.d.ts index 7f814195cfcd8..9fe8f63c28620 100644 --- a/src/lib/es2018.intl.d.ts +++ b/src/lib/es2018.intl.d.ts @@ -37,8 +37,9 @@ declare namespace Intl { supportedLocalesOf(locales: string | string[], options?: { localeMatcher?: "lookup" | "best fit" }): string[]; }; + type ES2018NumberFormatPartType = "literal" | "nan" | "infinity" | "percent" | "integer" | "group" | "decimal" | "fraction" | "plusSign" | "minusSign" | "percentSign" | "currency" | "code" | "symbol" | "name"; interface NumberFormatPart { - type: "literal" | "nan" | "infinity" | "percent" | "integer" | "group" | "decimal" | "fraction" | "plusSign" | "minusSign" | "percentSign" | "currency" | "code" | "symbol" | "name"; + type: ES2018NumberFormatPartType; value: string; } diff --git a/src/lib/es2020.intl.d.ts b/src/lib/es2020.intl.d.ts index edb886980ec4a..3a5c4958aa5e0 100644 --- a/src/lib/es2020.intl.d.ts +++ b/src/lib/es2020.intl.d.ts @@ -197,8 +197,9 @@ declare namespace Intl { ): UnicodeBCP47LocaleIdentifier[]; }; + type ES2020NumberFormatPartType = ES2018NumberFormatPartType | "compact" | "exponentInteger" | "exponentMinusSign" | "exponentSeparator" | "unit" | "unknown"; interface NumberFormatPart { - type: "compact" | "currency" | "decimal" | "exponentInteger" | "exponentMinusSign" | "exponentSeparator" | "fraction" | "group" | "infinity" | "integer" | "literal" | "minusSign" | "nan" | "plusSign" | "percentSign" | "unit" | "unknown"; + type: ES2020NumberFormatPartType } interface NumberFormatOptions { diff --git a/src/lib/es2021.intl.d.ts b/src/lib/es2021.intl.d.ts index d0652af1edbb9..30a84f43fae5a 100644 --- a/src/lib/es2021.intl.d.ts +++ b/src/lib/es2021.intl.d.ts @@ -1,7 +1,7 @@ declare namespace Intl { interface DateTimeFormatOptions { - formatMatcher?: "basic" | "best fit" | "best fit"; + formatMatcher?: "basic" | "best fit" | "best fit" | undefined; dateStyle?: "full" | "long" | "medium" | "short" | undefined; timeStyle?: "full" | "long" | "medium" | "short" | undefined; dayPeriod?: "narrow" | "short" | "long" | undefined;