Skip to content

Commit 41ab6bc

Browse files
committed
Add @@toStringTag to TS types
1 parent ad7e2e3 commit 41ab6bc

12 files changed

+35
-21
lines changed

index.d.ts

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,7 @@ export namespace Temporal {
520520
toLocaleString(locales?: string | string[], options?: Intl.DateTimeFormatOptions): string;
521521
toJSON(): string;
522522
toString(options?: ToStringPrecisionOptions): string;
523+
readonly [Symbol.toStringTag]: 'Temporal.Duration';
523524
}
524525

525526
/**
@@ -616,6 +617,7 @@ export namespace Temporal {
616617
toJSON(): string;
617618
toString(options?: InstantToStringOptions): string;
618619
valueOf(): never;
620+
readonly [Symbol.toStringTag]: 'Temporal.Instant';
619621
}
620622

621623
export interface CalendarProtocol {
@@ -779,6 +781,7 @@ export namespace Temporal {
779781
fields(fields: Iterable<string>): Iterable<string>;
780782
mergeFields(fields: Record<string, unknown>, additionalFields: Record<string, unknown>): Record<string, unknown>;
781783
toString(): string;
784+
readonly [Symbol.toStringTag]: 'Temporal.Calendar';
782785
}
783786

784787
export type PlainDateLike = {
@@ -875,6 +878,7 @@ export namespace Temporal {
875878
toJSON(): string;
876879
toString(options?: ShowCalendarOption): string;
877880
valueOf(): never;
881+
readonly [Symbol.toStringTag]: 'Temporal.PlainDate';
878882
}
879883

880884
export type PlainDateTimeLike = {
@@ -1044,6 +1048,7 @@ export namespace Temporal {
10441048
toJSON(): string;
10451049
toString(options?: CalendarTypeToStringOptions): string;
10461050
valueOf(): never;
1051+
readonly [Symbol.toStringTag]: 'Temporal.PlainDateTime';
10471052
}
10481053

10491054
export type PlainMonthDayLike = {
@@ -1078,6 +1083,7 @@ export namespace Temporal {
10781083
toJSON(): string;
10791084
toString(options?: ShowCalendarOption): string;
10801085
valueOf(): never;
1086+
readonly [Symbol.toStringTag]: 'Temporal.PlainMonthDay';
10811087
}
10821088

10831089
// Temporal.PlainTime's `calendar` field is a Temporal.Calendar, not a
@@ -1215,6 +1221,7 @@ export namespace Temporal {
12151221
toJSON(): string;
12161222
toString(options?: ToStringPrecisionOptions): string;
12171223
valueOf(): never;
1224+
readonly [Symbol.toStringTag]: 'Temporal.PlainTime';
12181225
}
12191226

12201227
/**
@@ -1272,6 +1279,7 @@ export namespace Temporal {
12721279
getPossibleInstantsFor(dateTime: Temporal.PlainDateTime | PlainDateTimeLike | string): Temporal.Instant[];
12731280
toString(): string;
12741281
toJSON(): string;
1282+
readonly [Symbol.toStringTag]: 'Temporal.TimeZone';
12751283
}
12761284

12771285
export type PlainYearMonthLike = {
@@ -1329,6 +1337,7 @@ export namespace Temporal {
13291337
toJSON(): string;
13301338
toString(options?: ShowCalendarOption): string;
13311339
valueOf(): never;
1340+
readonly [Symbol.toStringTag]: 'Temporal.PlainYearMonth';
13321341
}
13331342

13341343
export type ZonedDateTimeLike = {
@@ -1492,6 +1501,7 @@ export namespace Temporal {
14921501
toJSON(): string;
14931502
toString(options?: ZonedDateTimeToStringOptions): string;
14941503
valueOf(): never;
1504+
readonly [Symbol.toStringTag]: 'Temporal.ZonedDateTime';
14951505
}
14961506

14971507
/**
@@ -1500,7 +1510,7 @@ export namespace Temporal {
15001510
*
15011511
* See https://tc39.es/proposal-temporal/docs/now.html for more details.
15021512
*/
1503-
export namespace Now {
1513+
export const Now: {
15041514
/**
15051515
* Get the exact system date and time as a `Temporal.Instant`.
15061516
*
@@ -1513,7 +1523,7 @@ export namespace Temporal {
15131523
* exact time in a specific time zone, use `Temporal.Now.zonedDateTimeISO`
15141524
* or `Temporal.Now.zonedDateTime`.
15151525
* */
1516-
export function instant(): Temporal.Instant;
1526+
instant: () => Temporal.Instant;
15171527

15181528
/**
15191529
* Get the current calendar date and clock time in a specific calendar and
@@ -1533,10 +1543,7 @@ export namespace Temporal {
15331543
* object implementing the time zone protocol. If omitted, the environment's
15341544
* current time zone will be used.
15351545
*/
1536-
export function zonedDateTime(
1537-
calendar: CalendarProtocol | string,
1538-
tzLike?: TimeZoneProtocol | string
1539-
): Temporal.ZonedDateTime;
1546+
zonedDateTime: (calendar: CalendarProtocol | string, tzLike?: TimeZoneProtocol | string) => Temporal.ZonedDateTime;
15401547

15411548
/**
15421549
* Get the current calendar date and clock time in a specific time zone,
@@ -1548,7 +1555,7 @@ export namespace Temporal {
15481555
* object implementing the time zone protocol. If omitted, the environment's
15491556
* current time zone will be used.
15501557
*/
1551-
export function zonedDateTimeISO(tzLike?: TimeZoneProtocol | string): Temporal.ZonedDateTime;
1558+
zonedDateTimeISO: (tzLike?: TimeZoneProtocol | string) => Temporal.ZonedDateTime;
15521559

15531560
/**
15541561
* Get the current calendar date and clock time in a specific calendar and
@@ -1573,10 +1580,7 @@ export namespace Temporal {
15731580
* object implementing the time zone protocol. If omitted,
15741581
* the environment's current time zone will be used.
15751582
*/
1576-
export function plainDateTime(
1577-
calendar: CalendarProtocol | string,
1578-
tzLike?: TimeZoneProtocol | string
1579-
): Temporal.PlainDateTime;
1583+
plainDateTime: (calendar: CalendarProtocol | string, tzLike?: TimeZoneProtocol | string) => Temporal.PlainDateTime;
15801584

15811585
/**
15821586
* Get the current date and clock time in a specific time zone, using the
@@ -1593,7 +1597,7 @@ export namespace Temporal {
15931597
* object implementing the time zone protocol. If omitted, the environment's
15941598
* current time zone will be used.
15951599
*/
1596-
export function plainDateTimeISO(tzLike?: TimeZoneProtocol | string): Temporal.PlainDateTime;
1600+
plainDateTimeISO: (tzLike?: TimeZoneProtocol | string) => Temporal.PlainDateTime;
15971601

15981602
/**
15991603
* Get the current calendar date in a specific calendar and time zone.
@@ -1611,10 +1615,7 @@ export namespace Temporal {
16111615
* object implementing the time zone protocol. If omitted,
16121616
* the environment's current time zone will be used.
16131617
*/
1614-
export function plainDate(
1615-
calendar: CalendarProtocol | string,
1616-
tzLike?: TimeZoneProtocol | string
1617-
): Temporal.PlainDate;
1618+
plainDate: (calendar: CalendarProtocol | string, tzLike?: TimeZoneProtocol | string) => Temporal.PlainDate;
16181619

16191620
/**
16201621
* Get the current date in a specific time zone, using the ISO 8601
@@ -1626,7 +1627,7 @@ export namespace Temporal {
16261627
* object implementing the time zone protocol. If omitted, the environment's
16271628
* current time zone will be used.
16281629
*/
1629-
export function plainDateISO(tzLike?: TimeZoneProtocol | string): Temporal.PlainDate;
1630+
plainDateISO: (tzLike?: TimeZoneProtocol | string) => Temporal.PlainDate;
16301631

16311632
/**
16321633
* Get the current clock time in a specific time zone, using the ISO 8601 calendar.
@@ -1637,7 +1638,7 @@ export namespace Temporal {
16371638
* object implementing the time zone protocol. If omitted, the environment's
16381639
* current time zone will be used.
16391640
*/
1640-
export function plainTimeISO(tzLike?: TimeZoneProtocol | string): Temporal.PlainTime;
1641+
plainTimeISO: (tzLike?: TimeZoneProtocol | string) => Temporal.PlainTime;
16411642

16421643
/**
16431644
* Get the environment's current time zone.
@@ -1646,8 +1647,10 @@ export namespace Temporal {
16461647
* named
16471648
* {@link https://en.wikipedia.org/wiki/List_of_tz_database_time_zones|IANA time zone}.
16481649
*/
1649-
export function timeZone(): Temporal.TimeZone;
1650-
}
1650+
timeZone: () => Temporal.TimeZone;
1651+
1652+
readonly [Symbol.toStringTag]: 'Temporal.Now';
1653+
};
16511654
}
16521655

16531656
declare namespace IntlPolyfill {

lib/calendar.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ export class Calendar implements Temporal.Calendar {
227227
static from(item) {
228228
return ES.ToTemporalCalendar(item);
229229
}
230+
[Symbol.toStringTag]!: 'Temporal.Calendar';
230231
}
231232

232233
MakeIntrinsicClass(Calendar, 'Temporal.Calendar');

lib/duration.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,7 @@ export class Duration implements Temporal.Duration {
505505
ns2 = ES.TotalDurationNanoseconds(d2, h2, min2, s2, ms2, µs2, ns2, shift2);
506506
return ES.ComparisonResult(ns1.minus(ns2).toJSNumber());
507507
}
508+
[Symbol.toStringTag]!: 'Temporal.Duration';
508509
}
509510

510511
MakeIntrinsicClass(Duration, 'Temporal.Duration');

lib/instant.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,7 @@ export class Instant implements Temporal.Instant {
279279
if (bigInt(one).greater(two)) return 1;
280280
return 0;
281281
}
282+
[Symbol.toStringTag]!: 'Temporal.Instant';
282283
}
283284

284285
MakeIntrinsicClass(Instant, 'Temporal.Instant');

lib/now.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ export const Now: typeof Temporal.Now = {
4848
plainTimeISO,
4949
timeZone,
5050
zonedDateTime,
51-
zonedDateTimeISO
51+
zonedDateTimeISO,
52+
[Symbol.toStringTag]: 'Temporal.Now'
5253
};
5354
Object.defineProperty(Now, Symbol.toStringTag, {
5455
value: 'Temporal.Now',

lib/plaindate.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,7 @@ export class PlainDate implements Temporal.PlainDate {
417417
GetSlot(two, ISO_DAY)
418418
);
419419
}
420+
[Symbol.toStringTag]!: 'Temporal.PlainDate';
420421
}
421422

422423
MakeIntrinsicClass(PlainDate, 'Temporal.PlainDate');

lib/plaindatetime.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -701,6 +701,7 @@ export class PlainDateTime implements Temporal.PlainDateTime {
701701
}
702702
return 0;
703703
}
704+
[Symbol.toStringTag]!: 'Temporal.PlainDateTime';
704705
}
705706

706707
MakeIntrinsicClass(PlainDateTime, 'Temporal.PlainDateTime');

lib/plainmonthday.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ export class PlainMonthDay implements Temporal.PlainMonthDay {
144144
}
145145
return ES.ToTemporalMonthDay(item, options);
146146
}
147+
[Symbol.toStringTag]!: 'Temporal.PlainMonthDay';
147148
}
148149

149150
MakeIntrinsicClass(PlainMonthDay, 'Temporal.PlainMonthDay');

lib/plaintime.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,7 @@ export class PlainTime implements Temporal.PlainTime {
514514
}
515515
return 0;
516516
}
517+
[Symbol.toStringTag]!: 'Temporal.PlainTime';
517518
}
518519

519520
MakeIntrinsicClass(PlainTime, 'Temporal.PlainTime');

lib/plainyearmonth.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,7 @@ export class PlainYearMonth implements Temporal.PlainYearMonth {
362362
GetSlot(two, ISO_DAY)
363363
);
364364
}
365+
[Symbol.toStringTag]!: 'Temporal.PlainYearMonth';
365366
}
366367

367368
MakeIntrinsicClass(PlainYearMonth, 'Temporal.PlainYearMonth');

0 commit comments

Comments
 (0)