diff --git a/src/lib/es2020.intl.d.ts b/src/lib/es2020.intl.d.ts index c7d4d725368ea..9a548e9ec4fd7 100644 --- a/src/lib/es2020.intl.d.ts +++ b/src/lib/es2020.intl.d.ts @@ -63,7 +63,7 @@ declare namespace Intl { * * [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl#locales_argument). */ - type LocalesArgument = UnicodeBCP47LocaleIdentifier | UnicodeBCP47LocaleIdentifier[] | Locale | Locale[] | undefined; + type LocalesArgument = UnicodeBCP47LocaleIdentifier | Locale | (UnicodeBCP47LocaleIdentifier | Locale)[] | undefined; /** * An object with some or all of properties of `options` parameter @@ -295,30 +295,32 @@ declare namespace Intl { | "code" | "none"; - type ResolvedDisplayNamesType = + type DisplayNamesType = | "language" | "region" | "script" + | "calendar" + | "dateTimeField" | "currency"; - type DisplayNamesType = - | ResolvedDisplayNamesType - | "calendar" - | "datetimeField"; + type DisplayNamesLanguageDisplay = + | "dialect" + | "standard"; interface DisplayNamesOptions { - localeMatcher: RelativeTimeFormatLocaleMatcher; - style: RelativeTimeFormatStyle; + localeMatcher?: RelativeTimeFormatLocaleMatcher; + style?: RelativeTimeFormatStyle; type: DisplayNamesType; - languageDisplay: "dialect" | "standard"; - fallback: DisplayNamesFallback; + languageDisplay?: DisplayNamesLanguageDisplay; + fallback?: DisplayNamesFallback; } interface ResolvedDisplayNamesOptions { locale: UnicodeBCP47LocaleIdentifier; style: RelativeTimeFormatStyle; - type: ResolvedDisplayNamesType; + type: DisplayNamesType; fallback: DisplayNamesFallback; + languageDisplay?: DisplayNamesLanguageDisplay; } interface DisplayNames { @@ -365,7 +367,7 @@ declare namespace Intl { * * [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/DisplayNames). */ - new(locales?: BCP47LanguageTag | BCP47LanguageTag[], options?: Partial): DisplayNames; + new(locales: LocalesArgument, options: 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. @@ -380,7 +382,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?: LocalesArgument, options?: { localeMatcher?: RelativeTimeFormatLocaleMatcher }): BCP47LanguageTag[]; }; } diff --git a/tests/baselines/reference/es2020IntlAPIs.errors.txt b/tests/baselines/reference/es2020IntlAPIs.errors.txt index 0c74f13974c62..95b447d43f170 100644 --- a/tests/baselines/reference/es2020IntlAPIs.errors.txt +++ b/tests/baselines/reference/es2020IntlAPIs.errors.txt @@ -1,7 +1,11 @@ tests/cases/conformance/es2020/es2020IntlAPIs.ts(45,1): error TS2554: Expected 1-2 arguments, but got 0. +tests/cases/conformance/es2020/es2020IntlAPIs.ts(48,1): error TS2554: Expected 2 arguments, but got 0. +tests/cases/conformance/es2020/es2020IntlAPIs.ts(49,1): error TS2554: Expected 2 arguments, but got 1. +tests/cases/conformance/es2020/es2020IntlAPIs.ts(50,29): error TS2345: Argument of type '{}' is not assignable to parameter of type 'DisplayNamesOptions'. + Property 'type' is missing in type '{}' but required in type 'DisplayNamesOptions'. -==== tests/cases/conformance/es2020/es2020IntlAPIs.ts (1 errors) ==== +==== tests/cases/conformance/es2020/es2020IntlAPIs.ts (4 errors) ==== // 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"); @@ -50,4 +54,26 @@ tests/cases/conformance/es2020/es2020IntlAPIs.ts(45,1): error TS2554: Expected 1 ~~~~~~~~~~~~~~~~~ !!! error TS2554: Expected 1-2 arguments, but got 0. !!! related TS6210 /.ts/lib.es2020.intl.d.ts:311:14: An argument for 'tag' was not provided. - new Intl.Locale(new Intl.Locale('en-US')); \ No newline at end of file + new Intl.Locale(new Intl.Locale('en-US')); + + new Intl.DisplayNames(); // TypeError: invalid_argument + ~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2554: Expected 2 arguments, but got 0. +!!! related TS6210 /.ts/lib.es2020.intl.d.ts:390:13: An argument for 'locales' was not provided. + new Intl.DisplayNames('en'); // TypeError: invalid_argument + ~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2554: Expected 2 arguments, but got 1. +!!! related TS6210 /.ts/lib.es2020.intl.d.ts:390:39: An argument for 'options' was not provided. + new Intl.DisplayNames('en', {}); // TypeError: invalid_argument + ~~ +!!! error TS2345: Argument of type '{}' is not assignable to parameter of type 'DisplayNamesOptions'. +!!! error TS2345: Property 'type' is missing in type '{}' but required in type 'DisplayNamesOptions'. +!!! related TS2728 /.ts/lib.es2020.intl.d.ts:333:9: 'type' is declared here. + console.log((new Intl.DisplayNames(undefined, {type: 'language'})).of('en-GB')); // "British English" + + const localesArg = ["es-ES", new Intl.Locale("en-US")]; + console.log((new Intl.DisplayNames(localesArg, {type: 'language'})).resolvedOptions().locale); // "es-ES" + console.log(Intl.DisplayNames.supportedLocalesOf(localesArg)); // ["es-ES", "en-US"] + console.log(Intl.DisplayNames.supportedLocalesOf()); // [] + console.log(Intl.DisplayNames.supportedLocalesOf(localesArg, {})); // ["es-ES", "en-US"] + \ No newline at end of file diff --git a/tests/baselines/reference/es2020IntlAPIs.js b/tests/baselines/reference/es2020IntlAPIs.js index d08c2f427cdee..f440684ea2217 100644 --- a/tests/baselines/reference/es2020IntlAPIs.js +++ b/tests/baselines/reference/es2020IntlAPIs.js @@ -44,7 +44,19 @@ const options1 = { localeMatcher: 'lookup' } as const; console.log(Intl.DisplayNames.supportedLocalesOf(locales1, options1).join(', ')); new Intl.Locale(); // should error -new Intl.Locale(new Intl.Locale('en-US')); +new Intl.Locale(new Intl.Locale('en-US')); + +new Intl.DisplayNames(); // TypeError: invalid_argument +new Intl.DisplayNames('en'); // TypeError: invalid_argument +new Intl.DisplayNames('en', {}); // TypeError: invalid_argument +console.log((new Intl.DisplayNames(undefined, {type: 'language'})).of('en-GB')); // "British English" + +const localesArg = ["es-ES", new Intl.Locale("en-US")]; +console.log((new Intl.DisplayNames(localesArg, {type: 'language'})).resolvedOptions().locale); // "es-ES" +console.log(Intl.DisplayNames.supportedLocalesOf(localesArg)); // ["es-ES", "en-US"] +console.log(Intl.DisplayNames.supportedLocalesOf()); // [] +console.log(Intl.DisplayNames.supportedLocalesOf(localesArg, {})); // ["es-ES", "en-US"] + //// [es2020IntlAPIs.js] // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl#Locale_identification_and_negotiation @@ -78,3 +90,12 @@ const options1 = { localeMatcher: 'lookup' }; console.log(Intl.DisplayNames.supportedLocalesOf(locales1, options1).join(', ')); new Intl.Locale(); // should error new Intl.Locale(new Intl.Locale('en-US')); +new Intl.DisplayNames(); // TypeError: invalid_argument +new Intl.DisplayNames('en'); // TypeError: invalid_argument +new Intl.DisplayNames('en', {}); // TypeError: invalid_argument +console.log((new Intl.DisplayNames(undefined, { type: 'language' })).of('en-GB')); // "British English" +const localesArg = ["es-ES", new Intl.Locale("en-US")]; +console.log((new Intl.DisplayNames(localesArg, { type: 'language' })).resolvedOptions().locale); // "es-ES" +console.log(Intl.DisplayNames.supportedLocalesOf(localesArg)); // ["es-ES", "en-US"] +console.log(Intl.DisplayNames.supportedLocalesOf()); // [] +console.log(Intl.DisplayNames.supportedLocalesOf(localesArg, {})); // ["es-ES", "en-US"] diff --git a/tests/baselines/reference/es2020IntlAPIs.symbols b/tests/baselines/reference/es2020IntlAPIs.symbols index 08986c4bf7d44..cb66c05131001 100644 --- a/tests/baselines/reference/es2020IntlAPIs.symbols +++ b/tests/baselines/reference/es2020IntlAPIs.symbols @@ -160,3 +160,82 @@ new Intl.Locale(new Intl.Locale('en-US')); >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, --, --)) >Locale : Symbol(Intl.Locale, Decl(lib.es2020.intl.d.ts, --, --), Decl(lib.es2020.intl.d.ts, --, --)) +new Intl.DisplayNames(); // TypeError: invalid_argument +>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, --, --)) + +new Intl.DisplayNames('en'); // TypeError: invalid_argument +>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, --, --)) + +new Intl.DisplayNames('en', {}); // TypeError: invalid_argument +>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, --, --)) + +console.log((new Intl.DisplayNames(undefined, {type: 'language'})).of('en-GB')); // "British English" +>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.DisplayNames(undefined, {type: 'language'})).of : Symbol(Intl.DisplayNames.of, 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, --, --)) +>undefined : Symbol(undefined) +>type : Symbol(type, Decl(es2020IntlAPIs.ts, 50, 47)) +>of : Symbol(Intl.DisplayNames.of, Decl(lib.es2020.intl.d.ts, --, --)) + +const localesArg = ["es-ES", new Intl.Locale("en-US")]; +>localesArg : Symbol(localesArg, Decl(es2020IntlAPIs.ts, 52, 5)) +>Intl.Locale : Symbol(Intl.Locale, 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, --, --)) +>Locale : Symbol(Intl.Locale, Decl(lib.es2020.intl.d.ts, --, --), Decl(lib.es2020.intl.d.ts, --, --)) + +console.log((new Intl.DisplayNames(localesArg, {type: 'language'})).resolvedOptions().locale); // "es-ES" +>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.DisplayNames(localesArg, {type: 'language'})).resolvedOptions().locale : Symbol(Intl.ResolvedDisplayNamesOptions.locale, Decl(lib.es2020.intl.d.ts, --, --)) +>(new Intl.DisplayNames(localesArg, {type: 'language'})).resolvedOptions : Symbol(Intl.DisplayNames.resolvedOptions, 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, --, --)) +>localesArg : Symbol(localesArg, Decl(es2020IntlAPIs.ts, 52, 5)) +>type : Symbol(type, Decl(es2020IntlAPIs.ts, 53, 48)) +>resolvedOptions : Symbol(Intl.DisplayNames.resolvedOptions, Decl(lib.es2020.intl.d.ts, --, --)) +>locale : Symbol(Intl.ResolvedDisplayNamesOptions.locale, Decl(lib.es2020.intl.d.ts, --, --)) + +console.log(Intl.DisplayNames.supportedLocalesOf(localesArg)); // ["es-ES", "en-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, --, --)) +>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, --, --)) +>localesArg : Symbol(localesArg, Decl(es2020IntlAPIs.ts, 52, 5)) + +console.log(Intl.DisplayNames.supportedLocalesOf()); // [] +>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 : 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, --, --)) + +console.log(Intl.DisplayNames.supportedLocalesOf(localesArg, {})); // ["es-ES", "en-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, --, --)) +>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, --, --)) +>localesArg : Symbol(localesArg, Decl(es2020IntlAPIs.ts, 52, 5)) + diff --git a/tests/baselines/reference/es2020IntlAPIs.types b/tests/baselines/reference/es2020IntlAPIs.types index fa7ab907a19fc..6014acbd0597b 100644 --- a/tests/baselines/reference/es2020IntlAPIs.types +++ b/tests/baselines/reference/es2020IntlAPIs.types @@ -128,9 +128,9 @@ console.log(rtf2.format(2, 'day')); 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.DisplayNames : { new (locales: Intl.LocalesArgument, options: Intl.DisplayNamesOptions): Intl.DisplayNames; prototype: Intl.DisplayNames; supportedLocalesOf(locales?: Intl.LocalesArgument, 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[]; } +>DisplayNames : { new (locales: Intl.LocalesArgument, options: Intl.DisplayNamesOptions): Intl.DisplayNames; prototype: Intl.DisplayNames; supportedLocalesOf(locales?: Intl.LocalesArgument, options?: { localeMatcher?: Intl.RelativeTimeFormatLocaleMatcher; }): string[]; } >['en'] : string[] >'en' : "en" >{ type: 'region' } : { type: "region"; } @@ -140,9 +140,9 @@ const regionNamesInEnglish = new Intl.DisplayNames(['en'], { type: '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.DisplayNames : { new (locales: Intl.LocalesArgument, options: Intl.DisplayNamesOptions): Intl.DisplayNames; prototype: Intl.DisplayNames; supportedLocalesOf(locales?: Intl.LocalesArgument, 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[]; } +>DisplayNames : { new (locales: Intl.LocalesArgument, options: Intl.DisplayNamesOptions): Intl.DisplayNames; prototype: Intl.DisplayNames; supportedLocalesOf(locales?: Intl.LocalesArgument, options?: { localeMatcher?: Intl.RelativeTimeFormatLocaleMatcher; }): string[]; } >['zh-Hant'] : string[] >'zh-Hant' : "zh-Hant" >{ type: 'region' } : { type: "region"; } @@ -197,11 +197,11 @@ console.log(Intl.DisplayNames.supportedLocalesOf(locales1, options1).join(', ')) >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.DisplayNames.supportedLocalesOf : (locales?: Intl.LocalesArgument, options?: { localeMatcher?: Intl.RelativeTimeFormatLocaleMatcher; }) => string[] +>Intl.DisplayNames : { new (locales: Intl.LocalesArgument, options: Intl.DisplayNamesOptions): Intl.DisplayNames; prototype: Intl.DisplayNames; supportedLocalesOf(locales?: Intl.LocalesArgument, 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[] +>DisplayNames : { new (locales: Intl.LocalesArgument, options: Intl.DisplayNamesOptions): Intl.DisplayNames; prototype: Intl.DisplayNames; supportedLocalesOf(locales?: Intl.LocalesArgument, options?: { localeMatcher?: Intl.RelativeTimeFormatLocaleMatcher; }): string[]; } +>supportedLocalesOf : (locales?: Intl.LocalesArgument, options?: { localeMatcher?: Intl.RelativeTimeFormatLocaleMatcher; }) => string[] >locales1 : string[] >options1 : { readonly localeMatcher: "lookup"; } >join : (separator?: string) => string @@ -224,3 +224,112 @@ new Intl.Locale(new Intl.Locale('en-US')); >Locale : new (tag: string | Intl.Locale, options?: Intl.LocaleOptions) => Intl.Locale >'en-US' : "en-US" +new Intl.DisplayNames(); // TypeError: invalid_argument +>new Intl.DisplayNames() : Intl.DisplayNames +>Intl.DisplayNames : { new (locales: Intl.LocalesArgument, options: Intl.DisplayNamesOptions): Intl.DisplayNames; prototype: Intl.DisplayNames; supportedLocalesOf(locales?: Intl.LocalesArgument, options?: { localeMatcher?: Intl.RelativeTimeFormatLocaleMatcher; }): string[]; } +>Intl : typeof Intl +>DisplayNames : { new (locales: Intl.LocalesArgument, options: Intl.DisplayNamesOptions): Intl.DisplayNames; prototype: Intl.DisplayNames; supportedLocalesOf(locales?: Intl.LocalesArgument, options?: { localeMatcher?: Intl.RelativeTimeFormatLocaleMatcher; }): string[]; } + +new Intl.DisplayNames('en'); // TypeError: invalid_argument +>new Intl.DisplayNames('en') : Intl.DisplayNames +>Intl.DisplayNames : { new (locales: Intl.LocalesArgument, options: Intl.DisplayNamesOptions): Intl.DisplayNames; prototype: Intl.DisplayNames; supportedLocalesOf(locales?: Intl.LocalesArgument, options?: { localeMatcher?: Intl.RelativeTimeFormatLocaleMatcher; }): string[]; } +>Intl : typeof Intl +>DisplayNames : { new (locales: Intl.LocalesArgument, options: Intl.DisplayNamesOptions): Intl.DisplayNames; prototype: Intl.DisplayNames; supportedLocalesOf(locales?: Intl.LocalesArgument, options?: { localeMatcher?: Intl.RelativeTimeFormatLocaleMatcher; }): string[]; } +>'en' : "en" + +new Intl.DisplayNames('en', {}); // TypeError: invalid_argument +>new Intl.DisplayNames('en', {}) : Intl.DisplayNames +>Intl.DisplayNames : { new (locales: Intl.LocalesArgument, options: Intl.DisplayNamesOptions): Intl.DisplayNames; prototype: Intl.DisplayNames; supportedLocalesOf(locales?: Intl.LocalesArgument, options?: { localeMatcher?: Intl.RelativeTimeFormatLocaleMatcher; }): string[]; } +>Intl : typeof Intl +>DisplayNames : { new (locales: Intl.LocalesArgument, options: Intl.DisplayNamesOptions): Intl.DisplayNames; prototype: Intl.DisplayNames; supportedLocalesOf(locales?: Intl.LocalesArgument, options?: { localeMatcher?: Intl.RelativeTimeFormatLocaleMatcher; }): string[]; } +>'en' : "en" +>{} : {} + +console.log((new Intl.DisplayNames(undefined, {type: 'language'})).of('en-GB')); // "British English" +>console.log((new Intl.DisplayNames(undefined, {type: 'language'})).of('en-GB')) : void +>console.log : (...data: any[]) => void +>console : Console +>log : (...data: any[]) => void +>(new Intl.DisplayNames(undefined, {type: 'language'})).of('en-GB') : string +>(new Intl.DisplayNames(undefined, {type: 'language'})).of : (code: string) => string +>(new Intl.DisplayNames(undefined, {type: 'language'})) : Intl.DisplayNames +>new Intl.DisplayNames(undefined, {type: 'language'}) : Intl.DisplayNames +>Intl.DisplayNames : { new (locales: Intl.LocalesArgument, options: Intl.DisplayNamesOptions): Intl.DisplayNames; prototype: Intl.DisplayNames; supportedLocalesOf(locales?: Intl.LocalesArgument, options?: { localeMatcher?: Intl.RelativeTimeFormatLocaleMatcher; }): string[]; } +>Intl : typeof Intl +>DisplayNames : { new (locales: Intl.LocalesArgument, options: Intl.DisplayNamesOptions): Intl.DisplayNames; prototype: Intl.DisplayNames; supportedLocalesOf(locales?: Intl.LocalesArgument, options?: { localeMatcher?: Intl.RelativeTimeFormatLocaleMatcher; }): string[]; } +>undefined : undefined +>{type: 'language'} : { type: "language"; } +>type : "language" +>'language' : "language" +>of : (code: string) => string +>'en-GB' : "en-GB" + +const localesArg = ["es-ES", new Intl.Locale("en-US")]; +>localesArg : (string | Intl.Locale)[] +>["es-ES", new Intl.Locale("en-US")] : (string | Intl.Locale)[] +>"es-ES" : "es-ES" +>new Intl.Locale("en-US") : Intl.Locale +>Intl.Locale : new (tag: string | Intl.Locale, options?: Intl.LocaleOptions) => Intl.Locale +>Intl : typeof Intl +>Locale : new (tag: string | Intl.Locale, options?: Intl.LocaleOptions) => Intl.Locale +>"en-US" : "en-US" + +console.log((new Intl.DisplayNames(localesArg, {type: 'language'})).resolvedOptions().locale); // "es-ES" +>console.log((new Intl.DisplayNames(localesArg, {type: 'language'})).resolvedOptions().locale) : void +>console.log : (...data: any[]) => void +>console : Console +>log : (...data: any[]) => void +>(new Intl.DisplayNames(localesArg, {type: 'language'})).resolvedOptions().locale : string +>(new Intl.DisplayNames(localesArg, {type: 'language'})).resolvedOptions() : Intl.ResolvedDisplayNamesOptions +>(new Intl.DisplayNames(localesArg, {type: 'language'})).resolvedOptions : () => Intl.ResolvedDisplayNamesOptions +>(new Intl.DisplayNames(localesArg, {type: 'language'})) : Intl.DisplayNames +>new Intl.DisplayNames(localesArg, {type: 'language'}) : Intl.DisplayNames +>Intl.DisplayNames : { new (locales: Intl.LocalesArgument, options: Intl.DisplayNamesOptions): Intl.DisplayNames; prototype: Intl.DisplayNames; supportedLocalesOf(locales?: Intl.LocalesArgument, options?: { localeMatcher?: Intl.RelativeTimeFormatLocaleMatcher; }): string[]; } +>Intl : typeof Intl +>DisplayNames : { new (locales: Intl.LocalesArgument, options: Intl.DisplayNamesOptions): Intl.DisplayNames; prototype: Intl.DisplayNames; supportedLocalesOf(locales?: Intl.LocalesArgument, options?: { localeMatcher?: Intl.RelativeTimeFormatLocaleMatcher; }): string[]; } +>localesArg : (string | Intl.Locale)[] +>{type: 'language'} : { type: "language"; } +>type : "language" +>'language' : "language" +>resolvedOptions : () => Intl.ResolvedDisplayNamesOptions +>locale : string + +console.log(Intl.DisplayNames.supportedLocalesOf(localesArg)); // ["es-ES", "en-US"] +>console.log(Intl.DisplayNames.supportedLocalesOf(localesArg)) : void +>console.log : (...data: any[]) => void +>console : Console +>log : (...data: any[]) => void +>Intl.DisplayNames.supportedLocalesOf(localesArg) : string[] +>Intl.DisplayNames.supportedLocalesOf : (locales?: Intl.LocalesArgument, options?: { localeMatcher?: Intl.RelativeTimeFormatLocaleMatcher; }) => string[] +>Intl.DisplayNames : { new (locales: Intl.LocalesArgument, options: Intl.DisplayNamesOptions): Intl.DisplayNames; prototype: Intl.DisplayNames; supportedLocalesOf(locales?: Intl.LocalesArgument, options?: { localeMatcher?: Intl.RelativeTimeFormatLocaleMatcher; }): string[]; } +>Intl : typeof Intl +>DisplayNames : { new (locales: Intl.LocalesArgument, options: Intl.DisplayNamesOptions): Intl.DisplayNames; prototype: Intl.DisplayNames; supportedLocalesOf(locales?: Intl.LocalesArgument, options?: { localeMatcher?: Intl.RelativeTimeFormatLocaleMatcher; }): string[]; } +>supportedLocalesOf : (locales?: Intl.LocalesArgument, options?: { localeMatcher?: Intl.RelativeTimeFormatLocaleMatcher; }) => string[] +>localesArg : (string | Intl.Locale)[] + +console.log(Intl.DisplayNames.supportedLocalesOf()); // [] +>console.log(Intl.DisplayNames.supportedLocalesOf()) : void +>console.log : (...data: any[]) => void +>console : Console +>log : (...data: any[]) => void +>Intl.DisplayNames.supportedLocalesOf() : string[] +>Intl.DisplayNames.supportedLocalesOf : (locales?: Intl.LocalesArgument, options?: { localeMatcher?: Intl.RelativeTimeFormatLocaleMatcher; }) => string[] +>Intl.DisplayNames : { new (locales: Intl.LocalesArgument, options: Intl.DisplayNamesOptions): Intl.DisplayNames; prototype: Intl.DisplayNames; supportedLocalesOf(locales?: Intl.LocalesArgument, options?: { localeMatcher?: Intl.RelativeTimeFormatLocaleMatcher; }): string[]; } +>Intl : typeof Intl +>DisplayNames : { new (locales: Intl.LocalesArgument, options: Intl.DisplayNamesOptions): Intl.DisplayNames; prototype: Intl.DisplayNames; supportedLocalesOf(locales?: Intl.LocalesArgument, options?: { localeMatcher?: Intl.RelativeTimeFormatLocaleMatcher; }): string[]; } +>supportedLocalesOf : (locales?: Intl.LocalesArgument, options?: { localeMatcher?: Intl.RelativeTimeFormatLocaleMatcher; }) => string[] + +console.log(Intl.DisplayNames.supportedLocalesOf(localesArg, {})); // ["es-ES", "en-US"] +>console.log(Intl.DisplayNames.supportedLocalesOf(localesArg, {})) : void +>console.log : (...data: any[]) => void +>console : Console +>log : (...data: any[]) => void +>Intl.DisplayNames.supportedLocalesOf(localesArg, {}) : string[] +>Intl.DisplayNames.supportedLocalesOf : (locales?: Intl.LocalesArgument, options?: { localeMatcher?: Intl.RelativeTimeFormatLocaleMatcher; }) => string[] +>Intl.DisplayNames : { new (locales: Intl.LocalesArgument, options: Intl.DisplayNamesOptions): Intl.DisplayNames; prototype: Intl.DisplayNames; supportedLocalesOf(locales?: Intl.LocalesArgument, options?: { localeMatcher?: Intl.RelativeTimeFormatLocaleMatcher; }): string[]; } +>Intl : typeof Intl +>DisplayNames : { new (locales: Intl.LocalesArgument, options: Intl.DisplayNamesOptions): Intl.DisplayNames; prototype: Intl.DisplayNames; supportedLocalesOf(locales?: Intl.LocalesArgument, options?: { localeMatcher?: Intl.RelativeTimeFormatLocaleMatcher; }): string[]; } +>supportedLocalesOf : (locales?: Intl.LocalesArgument, options?: { localeMatcher?: Intl.RelativeTimeFormatLocaleMatcher; }) => string[] +>localesArg : (string | Intl.Locale)[] +>{} : {} + diff --git a/tests/cases/conformance/es2020/es2020IntlAPIs.ts b/tests/cases/conformance/es2020/es2020IntlAPIs.ts index 70c52a0de3d3f..e9687257bfe01 100644 --- a/tests/cases/conformance/es2020/es2020IntlAPIs.ts +++ b/tests/cases/conformance/es2020/es2020IntlAPIs.ts @@ -45,4 +45,15 @@ const options1 = { localeMatcher: 'lookup' } as const; console.log(Intl.DisplayNames.supportedLocalesOf(locales1, options1).join(', ')); new Intl.Locale(); // should error -new Intl.Locale(new Intl.Locale('en-US')); \ No newline at end of file +new Intl.Locale(new Intl.Locale('en-US')); + +new Intl.DisplayNames(); // TypeError: invalid_argument +new Intl.DisplayNames('en'); // TypeError: invalid_argument +new Intl.DisplayNames('en', {}); // TypeError: invalid_argument +console.log((new Intl.DisplayNames(undefined, {type: 'language'})).of('en-GB')); // "British English" + +const localesArg = ["es-ES", new Intl.Locale("en-US")]; +console.log((new Intl.DisplayNames(localesArg, {type: 'language'})).resolvedOptions().locale); // "es-ES" +console.log(Intl.DisplayNames.supportedLocalesOf(localesArg)); // ["es-ES", "en-US"] +console.log(Intl.DisplayNames.supportedLocalesOf()); // [] +console.log(Intl.DisplayNames.supportedLocalesOf(localesArg, {})); // ["es-ES", "en-US"]