diff --git a/tsc/internal/bundled/libs/lib.esnext.temporal.d.ts b/tsc/internal/bundled/libs/lib.esnext.temporal.d.ts index 5f1293f455333..9591045df2481 100644 --- a/tsc/internal/bundled/libs/lib.esnext.temporal.d.ts +++ b/tsc/internal/bundled/libs/lib.esnext.temporal.d.ts @@ -275,6 +275,8 @@ declare namespace Temporal { offset?: "use" | "ignore" | "prefer" | "reject" | undefined; } + interface ZonedDateTimeToLocaleStringOptions extends Omit {} + interface ZonedDateTime { readonly calendarId: string; readonly timeZoneId: string; @@ -316,7 +318,7 @@ declare namespace Temporal { round(roundTo: RoundingOptions<"day" | TimeUnit>): ZonedDateTime; equals(other: ZonedDateTimeLike): boolean; toString(options?: ZonedDateTimeToStringOptions): string; - toLocaleString(locales?: Intl.LocalesArgument, options?: Intl.DateTimeFormatOptions): string; + toLocaleString(locales?: Intl.LocalesArgument, options?: ZonedDateTimeToLocaleStringOptions): string; toJSON(): string; valueOf(): never; startOfDay(): ZonedDateTime; diff --git a/tsc/testdata/baselines/reference/compiler/temporal.errors.txt b/tsc/testdata/baselines/reference/compiler/temporal.errors.txt index 59d4e125441bd..97b2cc39c6793 100644 --- a/tsc/testdata/baselines/reference/compiler/temporal.errors.txt +++ b/tsc/testdata/baselines/reference/compiler/temporal.errors.txt @@ -1,10 +1,13 @@ temporal.ts(25,13): error TS2339: Property 'year' does not exist on type 'Instant'. +temporal.ts(594,47): error TS2353: Object literal may only specify known properties, and 'timeZone' does not exist in type 'Omit'. temporal.ts(1504,8): error TS2339: Property 'month' does not exist on type 'PlainMonthDay'. temporal.ts(1514,8): error TS2339: Property 'month' does not exist on type 'PlainMonthDay'. temporal.ts(1520,8): error TS2339: Property 'month' does not exist on type 'PlainMonthDay'. +temporal.ts(1825,37): error TS2353: Object literal may only specify known properties, and 'timeZone' does not exist in type 'Omit'. +temporal.ts(1826,35): error TS2353: Object literal may only specify known properties, and 'timeZone' does not exist in type 'Omit'. -==== temporal.ts (4 errors) ==== +==== temporal.ts (7 errors) ==== /** * Test cases derived from documentation at tc39/proposal-temporal, * under the following license: @@ -601,6 +604,8 @@ temporal.ts(1520,8): error TS2339: Property 'month' does not exist on type 'Plai const options = { weekday: "long", year: "numeric", month: "long", day: "numeric" } as const; zdt.toLocaleString("de-DE", options); // => 'Sonntag, 1. Dezember 2019' /* WRONG */ zdt.toLocaleString("de-DE", { timeZone: "Pacific/Auckland" }); + ~~~~~~~~ +!!! error TS2353: Object literal may only specify known properties, and 'timeZone' does not exist in type 'Omit'. // => RangeError: Time zone option Pacific/Auckland does not match actual time zone Europe/Berlin zdt.withTimeZone("Pacific/Auckland").toLocaleString("de-DE"); // => '2.12.2019, 0:00:00 GMT+13' zdt.toLocaleString("en-US-u-nu-fullwide-hc-h12"); // => '12/1/2019, 12:00:00 PM GMT+1' @@ -1833,4 +1838,17 @@ temporal.ts(1520,8): error TS2339: Property 'month' does not exist on type 'Plai Temporal.Now.plainTimeISO(); // get the current wall-clock time in the system time zone and ISO-8601 calendar Temporal.Now.plainDateTimeISO(); // same as above, but return the DateTime in the ISO-8601 calendar } + + { + // https://github.com/microsoft/TypeScript/issues/64227 + const zdt = Temporal.Now.zonedDateTimeISO("America/Chicago"); + zdt.toLocaleString(undefined, { timeZone: "Europe/Berlin" }); + ~~~~~~~~ +!!! error TS2353: Object literal may only specify known properties, and 'timeZone' does not exist in type 'Omit'. + zdt.toLocaleString("en-US", { timeZone: "Europe/Berlin" }); + ~~~~~~~~ +!!! error TS2353: Object literal may only specify known properties, and 'timeZone' does not exist in type 'Omit'. + zdt.toLocaleString(undefined, { month: "long" }); + zdt.toLocaleString("en-US", { month: "numeric", year: "numeric" }); + } \ No newline at end of file diff --git a/tsc/testdata/baselines/reference/compiler/temporal.js b/tsc/testdata/baselines/reference/compiler/temporal.js index 951ddf52662ec..3a66032caf3f3 100644 --- a/tsc/testdata/baselines/reference/compiler/temporal.js +++ b/tsc/testdata/baselines/reference/compiler/temporal.js @@ -1821,6 +1821,15 @@ Temporal.Now.plainTimeISO(); // get the current wall-clock time in the system time zone and ISO-8601 calendar Temporal.Now.plainDateTimeISO(); // same as above, but return the DateTime in the ISO-8601 calendar } + +{ + // https://github.com/microsoft/TypeScript/issues/64227 + const zdt = Temporal.Now.zonedDateTimeISO("America/Chicago"); + zdt.toLocaleString(undefined, { timeZone: "Europe/Berlin" }); + zdt.toLocaleString("en-US", { timeZone: "Europe/Berlin" }); + zdt.toLocaleString(undefined, { month: "long" }); + zdt.toLocaleString("en-US", { month: "numeric", year: "numeric" }); +} //// [temporal.js] @@ -3371,3 +3380,11 @@ Temporal.Now.plainTimeISO(); // get the current wall-clock time in the system time zone and ISO-8601 calendar Temporal.Now.plainDateTimeISO(); // same as above, but return the DateTime in the ISO-8601 calendar } +{ + // https://github.com/microsoft/TypeScript/issues/64227 + const zdt = Temporal.Now.zonedDateTimeISO("America/Chicago"); + zdt.toLocaleString(undefined, { timeZone: "Europe/Berlin" }); + zdt.toLocaleString("en-US", { timeZone: "Europe/Berlin" }); + zdt.toLocaleString(undefined, { month: "long" }); + zdt.toLocaleString("en-US", { month: "numeric", year: "numeric" }); +} diff --git a/tsc/testdata/baselines/reference/compiler/temporal.symbols b/tsc/testdata/baselines/reference/compiler/temporal.symbols index f232e7509e447..4192d7ad92cea 100644 --- a/tsc/testdata/baselines/reference/compiler/temporal.symbols +++ b/tsc/testdata/baselines/reference/compiler/temporal.symbols @@ -7029,3 +7029,41 @@ >plainDateTimeISO : Symbol(Temporal.Now.plainDateTimeISO, Decl(lib.esnext.temporal.d.ts, --, --)) } +{ + // https://github.com/microsoft/TypeScript/issues/64227 + const zdt = Temporal.Now.zonedDateTimeISO("America/Chicago"); +>zdt : Symbol(zdt, Decl(temporal.ts, 1823, 9)) +>Temporal.Now.zonedDateTimeISO : Symbol(Temporal.Now.zonedDateTimeISO, Decl(lib.esnext.temporal.d.ts, --, --)) +>Temporal.Now : Symbol(Temporal.Now, Decl(lib.esnext.temporal.d.ts, --, --)) +>Temporal : Symbol(Temporal, Decl(lib.esnext.temporal.d.ts, --, --)) +>Now : Symbol(Temporal.Now, Decl(lib.esnext.temporal.d.ts, --, --)) +>zonedDateTimeISO : Symbol(Temporal.Now.zonedDateTimeISO, Decl(lib.esnext.temporal.d.ts, --, --)) + + zdt.toLocaleString(undefined, { timeZone: "Europe/Berlin" }); +>zdt.toLocaleString : Symbol(Temporal.ZonedDateTime.toLocaleString, Decl(lib.esnext.temporal.d.ts, --, --)) +>zdt : Symbol(zdt, Decl(temporal.ts, 1823, 9)) +>toLocaleString : Symbol(Temporal.ZonedDateTime.toLocaleString, Decl(lib.esnext.temporal.d.ts, --, --)) +>undefined : Symbol(undefined) +>timeZone : Symbol(timeZone, Decl(temporal.ts, 1824, 35)) + + zdt.toLocaleString("en-US", { timeZone: "Europe/Berlin" }); +>zdt.toLocaleString : Symbol(Temporal.ZonedDateTime.toLocaleString, Decl(lib.esnext.temporal.d.ts, --, --)) +>zdt : Symbol(zdt, Decl(temporal.ts, 1823, 9)) +>toLocaleString : Symbol(Temporal.ZonedDateTime.toLocaleString, Decl(lib.esnext.temporal.d.ts, --, --)) +>timeZone : Symbol(timeZone, Decl(temporal.ts, 1825, 33)) + + zdt.toLocaleString(undefined, { month: "long" }); +>zdt.toLocaleString : Symbol(Temporal.ZonedDateTime.toLocaleString, Decl(lib.esnext.temporal.d.ts, --, --)) +>zdt : Symbol(zdt, Decl(temporal.ts, 1823, 9)) +>toLocaleString : Symbol(Temporal.ZonedDateTime.toLocaleString, Decl(lib.esnext.temporal.d.ts, --, --)) +>undefined : Symbol(undefined) +>month : Symbol(month, Decl(temporal.ts, 1826, 35)) + + zdt.toLocaleString("en-US", { month: "numeric", year: "numeric" }); +>zdt.toLocaleString : Symbol(Temporal.ZonedDateTime.toLocaleString, Decl(lib.esnext.temporal.d.ts, --, --)) +>zdt : Symbol(zdt, Decl(temporal.ts, 1823, 9)) +>toLocaleString : Symbol(Temporal.ZonedDateTime.toLocaleString, Decl(lib.esnext.temporal.d.ts, --, --)) +>month : Symbol(month, Decl(temporal.ts, 1827, 33)) +>year : Symbol(year, Decl(temporal.ts, 1827, 51)) +} + diff --git a/tsc/testdata/baselines/reference/compiler/temporal.types b/tsc/testdata/baselines/reference/compiler/temporal.types index 311de7546db8f..022beb10ada38 100644 --- a/tsc/testdata/baselines/reference/compiler/temporal.types +++ b/tsc/testdata/baselines/reference/compiler/temporal.types @@ -1598,9 +1598,9 @@ >zdt => zdt.toLocaleString("en", { month: "long" }) : (zdt: Temporal.ZonedDateTime) => string >zdt : Temporal.ZonedDateTime >zdt.toLocaleString("en", { month: "long" }) : string ->zdt.toLocaleString : (locales?: Intl.LocalesArgument, options?: Intl.DateTimeFormatOptions) => string +>zdt.toLocaleString : (locales?: Intl.LocalesArgument, options?: Temporal.ZonedDateTimeToLocaleStringOptions) => string >zdt : Temporal.ZonedDateTime ->toLocaleString : (locales?: Intl.LocalesArgument, options?: Intl.DateTimeFormatOptions) => string +>toLocaleString : (locales?: Intl.LocalesArgument, options?: Temporal.ZonedDateTimeToLocaleStringOptions) => string >"en" : "en" >{ month: "long" } : { month: "long"; } >month : "long" @@ -2604,15 +2604,15 @@ zdt.toLocaleString(); // example output: 12/1/2019, 12:00:00 PM >zdt.toLocaleString() : string ->zdt.toLocaleString : (locales?: Intl.LocalesArgument, options?: Intl.DateTimeFormatOptions) => string +>zdt.toLocaleString : (locales?: Intl.LocalesArgument, options?: Temporal.ZonedDateTimeToLocaleStringOptions) => string >zdt : Temporal.ZonedDateTime ->toLocaleString : (locales?: Intl.LocalesArgument, options?: Intl.DateTimeFormatOptions) => string +>toLocaleString : (locales?: Intl.LocalesArgument, options?: Temporal.ZonedDateTimeToLocaleStringOptions) => string zdt.toLocaleString("de-DE"); // => '1.12.2019, 12:00:00 MEZ' >zdt.toLocaleString("de-DE") : string ->zdt.toLocaleString : (locales?: Intl.LocalesArgument, options?: Intl.DateTimeFormatOptions) => string +>zdt.toLocaleString : (locales?: Intl.LocalesArgument, options?: Temporal.ZonedDateTimeToLocaleStringOptions) => string >zdt : Temporal.ZonedDateTime ->toLocaleString : (locales?: Intl.LocalesArgument, options?: Intl.DateTimeFormatOptions) => string +>toLocaleString : (locales?: Intl.LocalesArgument, options?: Temporal.ZonedDateTimeToLocaleStringOptions) => string >"de-DE" : "de-DE" const options = { weekday: "long", year: "numeric", month: "long", day: "numeric" } as const; @@ -2630,17 +2630,17 @@ zdt.toLocaleString("de-DE", options); // => 'Sonntag, 1. Dezember 2019' >zdt.toLocaleString("de-DE", options) : string ->zdt.toLocaleString : (locales?: Intl.LocalesArgument, options?: Intl.DateTimeFormatOptions) => string +>zdt.toLocaleString : (locales?: Intl.LocalesArgument, options?: Temporal.ZonedDateTimeToLocaleStringOptions) => string >zdt : Temporal.ZonedDateTime ->toLocaleString : (locales?: Intl.LocalesArgument, options?: Intl.DateTimeFormatOptions) => string +>toLocaleString : (locales?: Intl.LocalesArgument, options?: Temporal.ZonedDateTimeToLocaleStringOptions) => string >"de-DE" : "de-DE" >options : { readonly weekday: "long"; readonly year: "numeric"; readonly month: "long"; readonly day: "numeric"; } /* WRONG */ zdt.toLocaleString("de-DE", { timeZone: "Pacific/Auckland" }); >zdt.toLocaleString("de-DE", { timeZone: "Pacific/Auckland" }) : string ->zdt.toLocaleString : (locales?: Intl.LocalesArgument, options?: Intl.DateTimeFormatOptions) => string +>zdt.toLocaleString : (locales?: Intl.LocalesArgument, options?: Temporal.ZonedDateTimeToLocaleStringOptions) => string >zdt : Temporal.ZonedDateTime ->toLocaleString : (locales?: Intl.LocalesArgument, options?: Intl.DateTimeFormatOptions) => string +>toLocaleString : (locales?: Intl.LocalesArgument, options?: Temporal.ZonedDateTimeToLocaleStringOptions) => string >"de-DE" : "de-DE" >{ timeZone: "Pacific/Auckland" } : { timeZone: string; } >timeZone : string @@ -2649,20 +2649,20 @@ // => RangeError: Time zone option Pacific/Auckland does not match actual time zone Europe/Berlin zdt.withTimeZone("Pacific/Auckland").toLocaleString("de-DE"); // => '2.12.2019, 0:00:00 GMT+13' >zdt.withTimeZone("Pacific/Auckland").toLocaleString("de-DE") : string ->zdt.withTimeZone("Pacific/Auckland").toLocaleString : (locales?: Intl.LocalesArgument, options?: Intl.DateTimeFormatOptions) => string +>zdt.withTimeZone("Pacific/Auckland").toLocaleString : (locales?: Intl.LocalesArgument, options?: Temporal.ZonedDateTimeToLocaleStringOptions) => string >zdt.withTimeZone("Pacific/Auckland") : Temporal.ZonedDateTime >zdt.withTimeZone : (timeZone: Temporal.TimeZoneLike) => Temporal.ZonedDateTime >zdt : Temporal.ZonedDateTime >withTimeZone : (timeZone: Temporal.TimeZoneLike) => Temporal.ZonedDateTime >"Pacific/Auckland" : "Pacific/Auckland" ->toLocaleString : (locales?: Intl.LocalesArgument, options?: Intl.DateTimeFormatOptions) => string +>toLocaleString : (locales?: Intl.LocalesArgument, options?: Temporal.ZonedDateTimeToLocaleStringOptions) => string >"de-DE" : "de-DE" zdt.toLocaleString("en-US-u-nu-fullwide-hc-h12"); // => '12/1/2019, 12:00:00 PM GMT+1' >zdt.toLocaleString("en-US-u-nu-fullwide-hc-h12") : string ->zdt.toLocaleString : (locales?: Intl.LocalesArgument, options?: Intl.DateTimeFormatOptions) => string +>zdt.toLocaleString : (locales?: Intl.LocalesArgument, options?: Temporal.ZonedDateTimeToLocaleStringOptions) => string >zdt : Temporal.ZonedDateTime ->toLocaleString : (locales?: Intl.LocalesArgument, options?: Intl.DateTimeFormatOptions) => string +>toLocaleString : (locales?: Intl.LocalesArgument, options?: Temporal.ZonedDateTimeToLocaleStringOptions) => string >"en-US-u-nu-fullwide-hc-h12" : "en-US-u-nu-fullwide-hc-h12" } @@ -9126,3 +9126,58 @@ >plainDateTimeISO : (timeZone?: Temporal.TimeZoneLike) => Temporal.PlainDateTime } +{ + // https://github.com/microsoft/TypeScript/issues/64227 + const zdt = Temporal.Now.zonedDateTimeISO("America/Chicago"); +>zdt : Temporal.ZonedDateTime +>Temporal.Now.zonedDateTimeISO("America/Chicago") : Temporal.ZonedDateTime +>Temporal.Now.zonedDateTimeISO : (timeZone?: Temporal.TimeZoneLike) => Temporal.ZonedDateTime +>Temporal.Now : typeof Temporal.Now +>Temporal : typeof Temporal +>Now : typeof Temporal.Now +>zonedDateTimeISO : (timeZone?: Temporal.TimeZoneLike) => Temporal.ZonedDateTime +>"America/Chicago" : "America/Chicago" + + zdt.toLocaleString(undefined, { timeZone: "Europe/Berlin" }); +>zdt.toLocaleString(undefined, { timeZone: "Europe/Berlin" }) : string +>zdt.toLocaleString : (locales?: Intl.LocalesArgument, options?: Temporal.ZonedDateTimeToLocaleStringOptions) => string +>zdt : Temporal.ZonedDateTime +>toLocaleString : (locales?: Intl.LocalesArgument, options?: Temporal.ZonedDateTimeToLocaleStringOptions) => string +>undefined : undefined +>{ timeZone: "Europe/Berlin" } : { timeZone: string; } +>timeZone : string +>"Europe/Berlin" : "Europe/Berlin" + + zdt.toLocaleString("en-US", { timeZone: "Europe/Berlin" }); +>zdt.toLocaleString("en-US", { timeZone: "Europe/Berlin" }) : string +>zdt.toLocaleString : (locales?: Intl.LocalesArgument, options?: Temporal.ZonedDateTimeToLocaleStringOptions) => string +>zdt : Temporal.ZonedDateTime +>toLocaleString : (locales?: Intl.LocalesArgument, options?: Temporal.ZonedDateTimeToLocaleStringOptions) => string +>"en-US" : "en-US" +>{ timeZone: "Europe/Berlin" } : { timeZone: string; } +>timeZone : string +>"Europe/Berlin" : "Europe/Berlin" + + zdt.toLocaleString(undefined, { month: "long" }); +>zdt.toLocaleString(undefined, { month: "long" }) : string +>zdt.toLocaleString : (locales?: Intl.LocalesArgument, options?: Temporal.ZonedDateTimeToLocaleStringOptions) => string +>zdt : Temporal.ZonedDateTime +>toLocaleString : (locales?: Intl.LocalesArgument, options?: Temporal.ZonedDateTimeToLocaleStringOptions) => string +>undefined : undefined +>{ month: "long" } : { month: "long"; } +>month : "long" +>"long" : "long" + + zdt.toLocaleString("en-US", { month: "numeric", year: "numeric" }); +>zdt.toLocaleString("en-US", { month: "numeric", year: "numeric" }) : string +>zdt.toLocaleString : (locales?: Intl.LocalesArgument, options?: Temporal.ZonedDateTimeToLocaleStringOptions) => string +>zdt : Temporal.ZonedDateTime +>toLocaleString : (locales?: Intl.LocalesArgument, options?: Temporal.ZonedDateTimeToLocaleStringOptions) => string +>"en-US" : "en-US" +>{ month: "numeric", year: "numeric" } : { month: "numeric"; year: "numeric"; } +>month : "numeric" +>"numeric" : "numeric" +>year : "numeric" +>"numeric" : "numeric" +} + diff --git a/tsc/testdata/tests/cases/compiler/temporal.ts b/tsc/testdata/tests/cases/compiler/temporal.ts index e4c4d9472fd2b..14f7e88aec1cf 100644 --- a/tsc/testdata/tests/cases/compiler/temporal.ts +++ b/tsc/testdata/tests/cases/compiler/temporal.ts @@ -1822,3 +1822,12 @@ Temporal.Now.plainTimeISO(); // get the current wall-clock time in the system time zone and ISO-8601 calendar Temporal.Now.plainDateTimeISO(); // same as above, but return the DateTime in the ISO-8601 calendar } + +{ + // https://github.com/microsoft/TypeScript/issues/64227 + const zdt = Temporal.Now.zonedDateTimeISO("America/Chicago"); + zdt.toLocaleString(undefined, { timeZone: "Europe/Berlin" }); + zdt.toLocaleString("en-US", { timeZone: "Europe/Berlin" }); + zdt.toLocaleString(undefined, { month: "long" }); + zdt.toLocaleString("en-US", { month: "numeric", year: "numeric" }); +}