Intl 2021 Updates (#45647)

* Import of Intl.Locale from #39664

* Handle updating es2020.intl and add es2021 for new DateTimeFormatOptions options - re: #39664

* Extends DateTimeFormatOptions for new Intl APIs - re: #45420

* Handle migrating Intl.NumberFormat.formatToParts to es2018 (keeping esnext.intl around)

* Adds Intl.DisplayNames to es2020 - re: #44022

* Remove attributes added in es2021 from es2020 - re: #42944

* Add a reference to es2021 in the command line parser

* Adds some docs about the lib files

* Baselines

* Allow undefined in Intl inputs to allow for ergonomic usage of exactOptionalPropertyTypes - see #45652

* Adds some tests covering the APIs

* Apply suggestions from code review

Co-authored-by: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com>

* Handle PR feedback

* More review improvements

Co-authored-by: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com>
This commit is contained in:
Orta Therox 2021-09-08 09:43:01 +00:00 committed by GitHub
parent 32168ed653
commit 07fd7bce64
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
27 changed files with 926 additions and 269 deletions

1
lib/lib.es2021.d.ts vendored
View File

@ -22,3 +22,4 @@ and limitations under the License.
/// <reference lib="es2021.promise" />
/// <reference lib="es2021.string" />
/// <reference lib="es2021.weakref" />
/// <reference lib="es2021.intl" />

View File

@ -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"],

View File

@ -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/)
## 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 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 asked that APIs are available un-prefixed/flagged in at least 2 browser _engines_ (i.e. not just 2 chromium browsers.)
## Generated files
Any 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).
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/TypeScript-DOM-lib-generator).

View File

@ -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,9 +33,17 @@ 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[];
};
type ES2018NumberFormatPartType = "literal" | "nan" | "infinity" | "percent" | "integer" | "group" | "decimal" | "fraction" | "plusSign" | "minusSign" | "percentSign" | "currency" | "code" | "symbol" | "name";
interface NumberFormatPart {
type: ES2018NumberFormatPartType;
value: string;
}
interface NumberFormat {
formatToParts(number?: number | bigint): NumberFormatPart[];
}
}

View File

@ -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,26 +11,29 @@ 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"
| "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.
*
* [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 +41,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,33 +48,37 @@ 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;
}
/**
* 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).
*
* [Specification](https://tc39.es/ecma402/#table-relativetimeformat-resolvedoptions-properties)
*/
interface ResolvedRelativeTimeFormatOptions {
locale: UnicodeBCP47LocaleIdentifier;
@ -88,8 +92,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 +108,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 +116,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;
}
@ -183,41 +151,22 @@ 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).
*
* [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 +184,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[],
@ -261,29 +197,157 @@ declare namespace Intl {
): UnicodeBCP47LocaleIdentifier[];
};
type ES2020NumberFormatPartType = ES2018NumberFormatPartType | "compact" | "exponentInteger" | "exponentMinusSign" | "exponentSeparator" | "unit" | "unknown";
interface NumberFormatPart {
type: ES2020NumberFormatPartType
}
interface NumberFormatOptions {
compactDisplay?: string;
notation?: string;
signDisplay?: string;
unit?: string;
unitDisplay?: string;
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 {
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 {
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;
calendar?: string | undefined;
dayPeriod?: "narrow" | "short" | "long" | undefined;
numberingSystem?: string | undefined;
dateStyle?: "full" | "long" | "medium" | "short" | undefined;
timeStyle?: "full" | "long" | "medium" | "short" | undefined;
hourCycle?: "h11" | "h12" | "h23" | "h24" | undefined;
}
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;
};
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<DisplayNamesOptions>): 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[];
};
}

15
src/lib/es2021.intl.d.ts vendored Normal file
View File

@ -0,0 +1,15 @@
declare namespace Intl {
interface DateTimeFormatOptions {
formatMatcher?: "basic" | "best fit" | "best fit" | undefined;
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[];
}
}

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

@ -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 {

View File

@ -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
}

View File

@ -51,6 +51,7 @@
"es2021.string",
"es2021.promise",
"es2021.weakref",
"es2021.intl",
"esnext.intl",
// Default libraries
"es5.full",

View File

@ -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))

View File

@ -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<any> = 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.

View File

@ -22,6 +22,7 @@ const testAsyncGenerator: AsyncGenerator<any> = null as any;
const testAsyncGeneratorFunction: AsyncGeneratorFunction = null as any;
const testAsyncIterable: AsyncIterable<any> = null as any;
const testAsyncIterableIterator: AsyncIterableIterator<any> = 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();

View File

@ -69,60 +69,61 @@ const testAsyncIterable: AsyncIterable<any> = null as any;
const testAsyncIterableIterator: AsyncIterableIterator<any> = null as any;
>testAsyncIterableIterator : Symbol(testAsyncIterableIterator, Decl(doYouNeedToChangeYourTargetLibraryES2016Plus.ts, 22, 5))
// es2019
const testArrayFlat = [].flat();
>testArrayFlat : Symbol(testArrayFlat, Decl(doYouNeedToChangeYourTargetLibraryES2016Plus.ts, 25, 5))
const testArrayFlatMap = [].flatMap();
>testArrayFlatMap : Symbol(testArrayFlatMap, Decl(doYouNeedToChangeYourTargetLibraryES2016Plus.ts, 26, 5))
const testObjectConstructorFromEntries = Object.fromEntries({});
>testObjectConstructorFromEntries : Symbol(testObjectConstructorFromEntries, Decl(doYouNeedToChangeYourTargetLibraryES2016Plus.ts, 27, 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))
const testStringTrimEnd = "".trimEnd();
>testStringTrimEnd : Symbol(testStringTrimEnd, Decl(doYouNeedToChangeYourTargetLibraryES2016Plus.ts, 29, 5))
const testStringTrimLeft = "".trimLeft();
>testStringTrimLeft : Symbol(testStringTrimLeft, Decl(doYouNeedToChangeYourTargetLibraryES2016Plus.ts, 30, 5))
const testStringTrimRight = "".trimRight();
>testStringTrimRight : Symbol(testStringTrimRight, Decl(doYouNeedToChangeYourTargetLibraryES2016Plus.ts, 31, 5))
const testSymbolDescription = Symbol("foo").description;
>testSymbolDescription : Symbol(testSymbolDescription, Decl(doYouNeedToChangeYourTargetLibraryES2016Plus.ts, 32, 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))
>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))
const testRegExpMatchAll = /matchAll/g[Symbol.matchAll]("matchAll");
>testRegExpMatchAll : Symbol(testRegExpMatchAll, Decl(doYouNeedToChangeYourTargetLibraryES2016Plus.ts, 37, 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))
// es2021
const testPromiseAny = Promise.any([]);
>testPromiseAny : Symbol(testPromiseAny, Decl(doYouNeedToChangeYourTargetLibraryES2016Plus.ts, 41, 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))
// esnext
const testNumberFormatFormatToParts = new Intl.NumberFormat("en-US").formatToParts();
>testNumberFormatFormatToParts : Symbol(testNumberFormatFormatToParts, Decl(doYouNeedToChangeYourTargetLibraryES2016Plus.ts, 45, 5))
>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, 26, 5))
const testArrayFlatMap = [].flatMap();
>testArrayFlatMap : Symbol(testArrayFlatMap, Decl(doYouNeedToChangeYourTargetLibraryES2016Plus.ts, 27, 5))
const testObjectConstructorFromEntries = Object.fromEntries({});
>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, 29, 5))
const testStringTrimEnd = "".trimEnd();
>testStringTrimEnd : Symbol(testStringTrimEnd, Decl(doYouNeedToChangeYourTargetLibraryES2016Plus.ts, 30, 5))
const testStringTrimLeft = "".trimLeft();
>testStringTrimLeft : Symbol(testStringTrimLeft, Decl(doYouNeedToChangeYourTargetLibraryES2016Plus.ts, 31, 5))
const testStringTrimRight = "".trimRight();
>testStringTrimRight : Symbol(testStringTrimRight, Decl(doYouNeedToChangeYourTargetLibraryES2016Plus.ts, 32, 5))
const testSymbolDescription = Symbol("foo").description;
>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, 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, 37, 5))
const testRegExpMatchAll = /matchAll/g[Symbol.matchAll]("matchAll");
>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, 39, 5))
// es2021
const testPromiseAny = Promise.any([]);
>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, 43, 5))
// esnext

View File

@ -147,6 +147,17 @@ const testAsyncIterableIterator: AsyncIterableIterator<any> = 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

View File

@ -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(', '));

View File

@ -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, --, --))

View File

@ -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
>', ' : ", "

View File

@ -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(', '));

View File

@ -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, --, --))

View File

@ -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.DisplayNamesOptions>): 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.DisplayNamesOptions>): 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.DisplayNamesOptions>): 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.DisplayNamesOptions>): 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.DisplayNamesOptions>): 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.DisplayNamesOptions>): 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
>', ' : ", "

View File

@ -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, --, --))

View File

@ -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.

View File

@ -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.

View File

@ -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.

View File

@ -23,6 +23,7 @@ const testAsyncGenerator: AsyncGenerator<any> = null as any;
const testAsyncGeneratorFunction: AsyncGeneratorFunction = null as any;
const testAsyncIterable: AsyncIterable<any> = null as any;
const testAsyncIterableIterator: AsyncIterableIterator<any> = 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();

View File

@ -0,0 +1,7 @@
// @target: 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(', '));

View File

@ -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(', '));