diff --git a/src/lib/es2020.intl.d.ts b/src/lib/es2020.intl.d.ts index ba57d2e8658..581e9fb15cd 100644 --- a/src/lib/es2020.intl.d.ts +++ b/src/lib/es2020.intl.d.ts @@ -288,7 +288,7 @@ declare namespace Intl { * [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale). */ const Locale: { - new (tag?: BCP47LanguageTag, options?: LocaleOptions): Locale; + new (tag: BCP47LanguageTag | Locale, options?: LocaleOptions): Locale; }; interface DisplayNamesOptions { diff --git a/tests/baselines/reference/es2020IntlAPIs.errors.txt b/tests/baselines/reference/es2020IntlAPIs.errors.txt new file mode 100644 index 00000000000..0c74f13974c --- /dev/null +++ b/tests/baselines/reference/es2020IntlAPIs.errors.txt @@ -0,0 +1,53 @@ +tests/cases/conformance/es2020/es2020IntlAPIs.ts(45,1): error TS2554: Expected 1-2 arguments, but got 0. + + +==== tests/cases/conformance/es2020/es2020IntlAPIs.ts (1 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"); + + 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(', ')); + + new Intl.Locale(); // should error + ~~~~~~~~~~~~~~~~~ +!!! 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 diff --git a/tests/baselines/reference/es2020IntlAPIs.js b/tests/baselines/reference/es2020IntlAPIs.js index 8136ff27ee0..d08c2f427cd 100644 --- a/tests/baselines/reference/es2020IntlAPIs.js +++ b/tests/baselines/reference/es2020IntlAPIs.js @@ -41,7 +41,10 @@ console.log(regionNamesInTraditionalChinese.of('US')); const locales1 = ['ban', 'id-u-co-pinyin', 'de-ID']; const options1 = { localeMatcher: 'lookup' } as const; -console.log(Intl.DisplayNames.supportedLocalesOf(locales1, options1).join(', ')); +console.log(Intl.DisplayNames.supportedLocalesOf(locales1, options1).join(', ')); + +new Intl.Locale(); // should error +new Intl.Locale(new Intl.Locale('en-US')); //// [es2020IntlAPIs.js] // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl#Locale_identification_and_negotiation @@ -73,3 +76,5 @@ console.log(regionNamesInTraditionalChinese.of('US')); const locales1 = ['ban', 'id-u-co-pinyin', 'de-ID']; 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')); diff --git a/tests/baselines/reference/es2020IntlAPIs.symbols b/tests/baselines/reference/es2020IntlAPIs.symbols index 1738ba245b9..08986c4bf7d 100644 --- a/tests/baselines/reference/es2020IntlAPIs.symbols +++ b/tests/baselines/reference/es2020IntlAPIs.symbols @@ -147,3 +147,16 @@ console.log(Intl.DisplayNames.supportedLocalesOf(locales1, options1).join(', ')) >options1 : Symbol(options1, Decl(es2020IntlAPIs.ts, 41, 5)) >join : Symbol(Array.join, Decl(lib.es5.d.ts, --, --)) +new Intl.Locale(); // should error +>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, --, --)) + +new Intl.Locale(new Intl.Locale('en-US')); +>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, --, --)) +>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, --, --)) + diff --git a/tests/baselines/reference/es2020IntlAPIs.types b/tests/baselines/reference/es2020IntlAPIs.types index 4a5332ed64c..fa7ab907a19 100644 --- a/tests/baselines/reference/es2020IntlAPIs.types +++ b/tests/baselines/reference/es2020IntlAPIs.types @@ -207,3 +207,20 @@ console.log(Intl.DisplayNames.supportedLocalesOf(locales1, options1).join(', ')) >join : (separator?: string) => string >', ' : ", " +new Intl.Locale(); // should error +>new Intl.Locale() : 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 + +new Intl.Locale(new Intl.Locale('en-US')); +>new Intl.Locale(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 +>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" + diff --git a/tests/baselines/reference/localesObjectArgument.types b/tests/baselines/reference/localesObjectArgument.types index a7a07a6ce6a..efaca6926db 100644 --- a/tests/baselines/reference/localesObjectArgument.types +++ b/tests/baselines/reference/localesObjectArgument.types @@ -2,25 +2,25 @@ const enUS = new Intl.Locale("en-US"); >enUS : Intl.Locale >new Intl.Locale("en-US") : Intl.Locale ->Intl.Locale : new (tag?: string, options?: Intl.LocaleOptions) => Intl.Locale +>Intl.Locale : new (tag: string | Intl.Locale, options?: Intl.LocaleOptions) => Intl.Locale >Intl : typeof Intl ->Locale : new (tag?: string, options?: Intl.LocaleOptions) => Intl.Locale +>Locale : new (tag: string | Intl.Locale, options?: Intl.LocaleOptions) => Intl.Locale >"en-US" : "en-US" const deDE = new Intl.Locale("de-DE"); >deDE : Intl.Locale >new Intl.Locale("de-DE") : Intl.Locale ->Intl.Locale : new (tag?: string, options?: Intl.LocaleOptions) => Intl.Locale +>Intl.Locale : new (tag: string | Intl.Locale, options?: Intl.LocaleOptions) => Intl.Locale >Intl : typeof Intl ->Locale : new (tag?: string, options?: Intl.LocaleOptions) => Intl.Locale +>Locale : new (tag: string | Intl.Locale, options?: Intl.LocaleOptions) => Intl.Locale >"de-DE" : "de-DE" const jaJP = new Intl.Locale("ja-JP"); >jaJP : Intl.Locale >new Intl.Locale("ja-JP") : Intl.Locale ->Intl.Locale : new (tag?: string, options?: Intl.LocaleOptions) => Intl.Locale +>Intl.Locale : new (tag: string | Intl.Locale, options?: Intl.LocaleOptions) => Intl.Locale >Intl : typeof Intl ->Locale : new (tag?: string, options?: Intl.LocaleOptions) => Intl.Locale +>Locale : new (tag: string | Intl.Locale, options?: Intl.LocaleOptions) => Intl.Locale >"ja-JP" : "ja-JP" const now = new Date(); diff --git a/tests/cases/conformance/es2020/es2020IntlAPIs.ts b/tests/cases/conformance/es2020/es2020IntlAPIs.ts index 464ecc01ecf..70c52a0de3d 100644 --- a/tests/cases/conformance/es2020/es2020IntlAPIs.ts +++ b/tests/cases/conformance/es2020/es2020IntlAPIs.ts @@ -42,4 +42,7 @@ console.log(regionNamesInTraditionalChinese.of('US')); const locales1 = ['ban', 'id-u-co-pinyin', 'de-ID']; const options1 = { localeMatcher: 'lookup' } as const; -console.log(Intl.DisplayNames.supportedLocalesOf(locales1, options1).join(', ')); \ No newline at end of file +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