Skip to content

Add Intl.Locale parameter type to toLocale[X]String signatures. #47811

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Feb 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/compiler/commandLineParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,13 @@ namespace ts {
["es2019.string", "lib.es2019.string.d.ts"],
["es2019.symbol", "lib.es2019.symbol.d.ts"],
["es2020.bigint", "lib.es2020.bigint.d.ts"],
["es2020.date", "lib.es2020.date.d.ts"],
["es2020.promise", "lib.es2020.promise.d.ts"],
["es2020.sharedmemory", "lib.es2020.sharedmemory.d.ts"],
["es2020.string", "lib.es2020.string.d.ts"],
["es2020.symbol.wellknown", "lib.es2020.symbol.wellknown.d.ts"],
["es2020.intl", "lib.es2020.intl.d.ts"],
["es2020.number", "lib.es2020.number.d.ts"],
["es2021.promise", "lib.es2021.promise.d.ts"],
["es2021.string", "lib.es2021.string.d.ts"],
["es2021.weakref", "lib.es2021.weakref.d.ts"],
Expand Down
4 changes: 3 additions & 1 deletion src/lib/es2020.bigint.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/// <reference lib="es2020.intl" />

interface BigIntToLocaleStringOptions {
/**
* The locale matching algorithm to use.The default is "best fit". For information about this option, see the {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl#Locale_negotiation Intl page}.
Expand Down Expand Up @@ -92,7 +94,7 @@ interface BigInt {
toString(radix?: number): string;

/** Returns a string representation appropriate to the host environment's current locale. */
toLocaleString(locales?: string, options?: BigIntToLocaleStringOptions): string;
toLocaleString(locales?: Intl.LocalesArgument, options?: BigIntToLocaleStringOptions): string;

/** Returns the primitive value of the specified object. */
valueOf(): bigint;
Expand Down
2 changes: 2 additions & 0 deletions src/lib/es2020.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/// <reference lib="es2019" />
/// <reference lib="es2020.bigint" />
/// <reference lib="es2020.date" />
/// <reference lib="es2020.number" />
/// <reference lib="es2020.promise" />
/// <reference lib="es2020.sharedmemory" />
/// <reference lib="es2020.string" />
Expand Down
24 changes: 24 additions & 0 deletions src/lib/es2020.date.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/// <reference lib="es2020.intl" />

interface Date {
/**
* Converts a date and time to a string by using the current or specified locale.
* @param locales A locale string, array of locale strings, Intl.Locale object, or array of Intl.Locale objects that contain one or more language or locale tags. If you include more than one locale string, list them in descending order of priority so that the first entry is the preferred locale. If you omit this parameter, the default locale of the JavaScript runtime is used.
* @param options An object that contains one or more properties that specify comparison options.
*/
toLocaleString(locales?: Intl.LocalesArgument, options?: Intl.DateTimeFormatOptions): string;

/**
* Converts a date to a string by using the current or specified locale.
* @param locales A locale string, array of locale strings, Intl.Locale object, or array of Intl.Locale objects that contain one or more language or locale tags. If you include more than one locale string, list them in descending order of priority so that the first entry is the preferred locale. If you omit this parameter, the default locale of the JavaScript runtime is used.
* @param options An object that contains one or more properties that specify comparison options.
*/
toLocaleDateString(locales?: Intl.LocalesArgument, options?: Intl.DateTimeFormatOptions): string;

/**
* Converts a time to a string by using the current or specified locale.
* @param locales A locale string, array of locale strings, Intl.Locale object, or array of Intl.Locale objects that contain one or more language or locale tags. If you include more than one locale string, list them in descending order of priority so that the first entry is the preferred locale. If you omit this parameter, the default locale of the JavaScript runtime is used.
* @param options An object that contains one or more properties that specify comparison options.
*/
toLocaleTimeString(locales?: Intl.LocalesArgument, options?: Intl.DateTimeFormatOptions): string;
}
7 changes: 7 additions & 0 deletions src/lib/es2020.intl.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@ declare namespace Intl {
*/
type BCP47LanguageTag = string;

/**
* The locale(s) to use
*
* [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl#locales_argument).
*/
type LocalesArgument = UnicodeBCP47LocaleIdentifier | UnicodeBCP47LocaleIdentifier[] | Locale | Locale[] | undefined;

/**
* An object with some or all of properties of `options` parameter
* of `Intl.RelativeTimeFormat` constructor.
Expand Down
10 changes: 10 additions & 0 deletions src/lib/es2020.number.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/// <reference lib="es2020.intl" />

interface Number {
/**
* Converts a number to a string by using the current or specified locale.
* @param locales A locale string, array of locale strings, Intl.Locale object, or array of Intl.Locale objects that contain one or more language or locale tags. If you include more than one locale string, list them in descending order of priority so that the first entry is the preferred locale. If you omit this parameter, the default locale of the JavaScript runtime is used.
* @param options An object that contains one or more properties that specify comparison options.
*/
toLocaleString(locales?: Intl.LocalesArgument, options?: Intl.NumberFormatOptions): string;
}
2 changes: 2 additions & 0 deletions src/lib/libs.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,13 @@
"es2019.string",
"es2019.symbol",
"es2020.bigint",
"es2020.date",
"es2020.promise",
"es2020.sharedmemory",
"es2020.string",
"es2020.symbol.wellknown",
"es2020.intl",
"es2020.number",
"es2021.string",
"es2021.promise",
"es2021.weakref",
Expand Down
16 changes: 8 additions & 8 deletions tests/baselines/reference/bigintWithLib.types
Original file line number Diff line number Diff line change
Expand Up @@ -66,26 +66,26 @@ stringVal = bigintVal.toLocaleString();
>stringVal = bigintVal.toLocaleString() : string
>stringVal : string
>bigintVal.toLocaleString() : string
>bigintVal.toLocaleString : (locales?: string, options?: BigIntToLocaleStringOptions) => string
>bigintVal.toLocaleString : (locales?: Intl.LocalesArgument, options?: BigIntToLocaleStringOptions) => string
>bigintVal : bigint
>toLocaleString : (locales?: string, options?: BigIntToLocaleStringOptions) => string
>toLocaleString : (locales?: Intl.LocalesArgument, options?: BigIntToLocaleStringOptions) => string

stringVal = bigintVal.toLocaleString('de-DE');
>stringVal = bigintVal.toLocaleString('de-DE') : string
>stringVal : string
>bigintVal.toLocaleString('de-DE') : string
>bigintVal.toLocaleString : (locales?: string, options?: BigIntToLocaleStringOptions) => string
>bigintVal.toLocaleString : (locales?: Intl.LocalesArgument, options?: BigIntToLocaleStringOptions) => string
>bigintVal : bigint
>toLocaleString : (locales?: string, options?: BigIntToLocaleStringOptions) => string
>toLocaleString : (locales?: Intl.LocalesArgument, options?: BigIntToLocaleStringOptions) => string
>'de-DE' : "de-DE"

stringVal = bigintVal.toLocaleString('de-DE', { style: 'currency' });
>stringVal = bigintVal.toLocaleString('de-DE', { style: 'currency' }) : string
>stringVal : string
>bigintVal.toLocaleString('de-DE', { style: 'currency' }) : string
>bigintVal.toLocaleString : (locales?: string, options?: BigIntToLocaleStringOptions) => string
>bigintVal.toLocaleString : (locales?: Intl.LocalesArgument, options?: BigIntToLocaleStringOptions) => string
>bigintVal : bigint
>toLocaleString : (locales?: string, options?: BigIntToLocaleStringOptions) => string
>toLocaleString : (locales?: Intl.LocalesArgument, options?: BigIntToLocaleStringOptions) => string
>'de-DE' : "de-DE"
>{ style: 'currency' } : { style: string; }
>style : string
Expand All @@ -95,9 +95,9 @@ stringVal = bigintVal.toLocaleString('de-DE', { style: 'currency', currency: 'EU
>stringVal = bigintVal.toLocaleString('de-DE', { style: 'currency', currency: 'EUR' }) : string
>stringVal : string
>bigintVal.toLocaleString('de-DE', { style: 'currency', currency: 'EUR' }) : string
>bigintVal.toLocaleString : (locales?: string, options?: BigIntToLocaleStringOptions) => string
>bigintVal.toLocaleString : (locales?: Intl.LocalesArgument, options?: BigIntToLocaleStringOptions) => string
>bigintVal : bigint
>toLocaleString : (locales?: string, options?: BigIntToLocaleStringOptions) => string
>toLocaleString : (locales?: Intl.LocalesArgument, options?: BigIntToLocaleStringOptions) => string
>'de-DE' : "de-DE"
>{ style: 'currency', currency: 'EUR' } : { style: string; currency: string; }
>style : string
Expand Down
2 changes: 1 addition & 1 deletion tests/baselines/reference/es2020IntlAPIs.symbols
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const count = 26254.39;

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, --, --))
>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, --, --) ... and 1 more)

function log(locale: string) {
>log : Symbol(log, Decl(es2020IntlAPIs.ts, 2, 36))
Expand Down
40 changes: 40 additions & 0 deletions tests/baselines/reference/localesObjectArgument.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
//// [localesObjectArgument.ts]
const enUS = new Intl.Locale("en-US");
const deDE = new Intl.Locale("de-DE");
const jaJP = new Intl.Locale("ja-JP");

const now = new Date();
const num = 1000;
const bigint = 123456789123456789n;

now.toLocaleString(enUS);
now.toLocaleDateString(enUS);
now.toLocaleTimeString(enUS);
now.toLocaleString([deDE, jaJP]);
now.toLocaleDateString([deDE, jaJP]);
now.toLocaleTimeString([deDE, jaJP]);

num.toLocaleString(enUS);
num.toLocaleString([deDE, jaJP]);

bigint.toLocaleString(enUS);
bigint.toLocaleString([deDE, jaJP]);


//// [localesObjectArgument.js]
const enUS = new Intl.Locale("en-US");
const deDE = new Intl.Locale("de-DE");
const jaJP = new Intl.Locale("ja-JP");
const now = new Date();
const num = 1000;
const bigint = 123456789123456789n;
now.toLocaleString(enUS);
now.toLocaleDateString(enUS);
now.toLocaleTimeString(enUS);
now.toLocaleString([deDE, jaJP]);
now.toLocaleDateString([deDE, jaJP]);
now.toLocaleTimeString([deDE, jaJP]);
num.toLocaleString(enUS);
num.toLocaleString([deDE, jaJP]);
bigint.toLocaleString(enUS);
bigint.toLocaleString([deDE, jaJP]);
94 changes: 94 additions & 0 deletions tests/baselines/reference/localesObjectArgument.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
=== tests/cases/conformance/es2020/localesObjectArgument.ts ===
const enUS = new Intl.Locale("en-US");
>enUS : Symbol(enUS, Decl(localesObjectArgument.ts, 0, 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, --, --))

const deDE = new Intl.Locale("de-DE");
>deDE : Symbol(deDE, Decl(localesObjectArgument.ts, 1, 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, --, --))

const jaJP = new Intl.Locale("ja-JP");
>jaJP : Symbol(jaJP, Decl(localesObjectArgument.ts, 2, 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, --, --))

const now = new Date();
>now : Symbol(now, Decl(localesObjectArgument.ts, 4, 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, --, --) ... and 1 more)

const num = 1000;
>num : Symbol(num, Decl(localesObjectArgument.ts, 5, 5))

const bigint = 123456789123456789n;
>bigint : Symbol(bigint, Decl(localesObjectArgument.ts, 6, 5))

now.toLocaleString(enUS);
>now.toLocaleString : Symbol(Date.toLocaleString, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2020.date.d.ts, --, --))
>now : Symbol(now, Decl(localesObjectArgument.ts, 4, 5))
>toLocaleString : Symbol(Date.toLocaleString, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2020.date.d.ts, --, --))
>enUS : Symbol(enUS, Decl(localesObjectArgument.ts, 0, 5))

now.toLocaleDateString(enUS);
>now.toLocaleDateString : Symbol(Date.toLocaleDateString, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2020.date.d.ts, --, --))
>now : Symbol(now, Decl(localesObjectArgument.ts, 4, 5))
>toLocaleDateString : Symbol(Date.toLocaleDateString, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2020.date.d.ts, --, --))
>enUS : Symbol(enUS, Decl(localesObjectArgument.ts, 0, 5))

now.toLocaleTimeString(enUS);
>now.toLocaleTimeString : Symbol(Date.toLocaleTimeString, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2020.date.d.ts, --, --))
>now : Symbol(now, Decl(localesObjectArgument.ts, 4, 5))
>toLocaleTimeString : Symbol(Date.toLocaleTimeString, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2020.date.d.ts, --, --))
>enUS : Symbol(enUS, Decl(localesObjectArgument.ts, 0, 5))

now.toLocaleString([deDE, jaJP]);
>now.toLocaleString : Symbol(Date.toLocaleString, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2020.date.d.ts, --, --))
>now : Symbol(now, Decl(localesObjectArgument.ts, 4, 5))
>toLocaleString : Symbol(Date.toLocaleString, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2020.date.d.ts, --, --))
>deDE : Symbol(deDE, Decl(localesObjectArgument.ts, 1, 5))
>jaJP : Symbol(jaJP, Decl(localesObjectArgument.ts, 2, 5))

now.toLocaleDateString([deDE, jaJP]);
>now.toLocaleDateString : Symbol(Date.toLocaleDateString, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2020.date.d.ts, --, --))
>now : Symbol(now, Decl(localesObjectArgument.ts, 4, 5))
>toLocaleDateString : Symbol(Date.toLocaleDateString, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2020.date.d.ts, --, --))
>deDE : Symbol(deDE, Decl(localesObjectArgument.ts, 1, 5))
>jaJP : Symbol(jaJP, Decl(localesObjectArgument.ts, 2, 5))

now.toLocaleTimeString([deDE, jaJP]);
>now.toLocaleTimeString : Symbol(Date.toLocaleTimeString, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2020.date.d.ts, --, --))
>now : Symbol(now, Decl(localesObjectArgument.ts, 4, 5))
>toLocaleTimeString : Symbol(Date.toLocaleTimeString, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2020.date.d.ts, --, --))
>deDE : Symbol(deDE, Decl(localesObjectArgument.ts, 1, 5))
>jaJP : Symbol(jaJP, Decl(localesObjectArgument.ts, 2, 5))

num.toLocaleString(enUS);
>num.toLocaleString : Symbol(Number.toLocaleString, Decl(lib.es5.d.ts, --, --), Decl(lib.es2020.number.d.ts, --, --))
>num : Symbol(num, Decl(localesObjectArgument.ts, 5, 5))
>toLocaleString : Symbol(Number.toLocaleString, Decl(lib.es5.d.ts, --, --), Decl(lib.es2020.number.d.ts, --, --))
>enUS : Symbol(enUS, Decl(localesObjectArgument.ts, 0, 5))

num.toLocaleString([deDE, jaJP]);
>num.toLocaleString : Symbol(Number.toLocaleString, Decl(lib.es5.d.ts, --, --), Decl(lib.es2020.number.d.ts, --, --))
>num : Symbol(num, Decl(localesObjectArgument.ts, 5, 5))
>toLocaleString : Symbol(Number.toLocaleString, Decl(lib.es5.d.ts, --, --), Decl(lib.es2020.number.d.ts, --, --))
>deDE : Symbol(deDE, Decl(localesObjectArgument.ts, 1, 5))
>jaJP : Symbol(jaJP, Decl(localesObjectArgument.ts, 2, 5))

bigint.toLocaleString(enUS);
>bigint.toLocaleString : Symbol(BigInt.toLocaleString, Decl(lib.es2020.bigint.d.ts, --, --))
>bigint : Symbol(bigint, Decl(localesObjectArgument.ts, 6, 5))
>toLocaleString : Symbol(BigInt.toLocaleString, Decl(lib.es2020.bigint.d.ts, --, --))
>enUS : Symbol(enUS, Decl(localesObjectArgument.ts, 0, 5))

bigint.toLocaleString([deDE, jaJP]);
>bigint.toLocaleString : Symbol(BigInt.toLocaleString, Decl(lib.es2020.bigint.d.ts, --, --))
>bigint : Symbol(bigint, Decl(localesObjectArgument.ts, 6, 5))
>toLocaleString : Symbol(BigInt.toLocaleString, Decl(lib.es2020.bigint.d.ts, --, --))
>deDE : Symbol(deDE, Decl(localesObjectArgument.ts, 1, 5))
>jaJP : Symbol(jaJP, Decl(localesObjectArgument.ts, 2, 5))

Loading