Skip to content

Commit

Permalink
Add @@toStringTag to TS types
Browse files Browse the repository at this point in the history
  • Loading branch information
justingrant committed Sep 22, 2021
1 parent ad7e2e3 commit 41ab6bc
Show file tree
Hide file tree
Showing 12 changed files with 35 additions and 21 deletions.
43 changes: 23 additions & 20 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,7 @@ export namespace Temporal {
toLocaleString(locales?: string | string[], options?: Intl.DateTimeFormatOptions): string;
toJSON(): string;
toString(options?: ToStringPrecisionOptions): string;
readonly [Symbol.toStringTag]: 'Temporal.Duration';
}

/**
Expand Down Expand Up @@ -616,6 +617,7 @@ export namespace Temporal {
toJSON(): string;
toString(options?: InstantToStringOptions): string;
valueOf(): never;
readonly [Symbol.toStringTag]: 'Temporal.Instant';
}

export interface CalendarProtocol {
Expand Down Expand Up @@ -779,6 +781,7 @@ export namespace Temporal {
fields(fields: Iterable<string>): Iterable<string>;
mergeFields(fields: Record<string, unknown>, additionalFields: Record<string, unknown>): Record<string, unknown>;
toString(): string;
readonly [Symbol.toStringTag]: 'Temporal.Calendar';
}

export type PlainDateLike = {
Expand Down Expand Up @@ -875,6 +878,7 @@ export namespace Temporal {
toJSON(): string;
toString(options?: ShowCalendarOption): string;
valueOf(): never;
readonly [Symbol.toStringTag]: 'Temporal.PlainDate';
}

export type PlainDateTimeLike = {
Expand Down Expand Up @@ -1044,6 +1048,7 @@ export namespace Temporal {
toJSON(): string;
toString(options?: CalendarTypeToStringOptions): string;
valueOf(): never;
readonly [Symbol.toStringTag]: 'Temporal.PlainDateTime';
}

export type PlainMonthDayLike = {
Expand Down Expand Up @@ -1078,6 +1083,7 @@ export namespace Temporal {
toJSON(): string;
toString(options?: ShowCalendarOption): string;
valueOf(): never;
readonly [Symbol.toStringTag]: 'Temporal.PlainMonthDay';
}

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

/**
Expand Down Expand Up @@ -1272,6 +1279,7 @@ export namespace Temporal {
getPossibleInstantsFor(dateTime: Temporal.PlainDateTime | PlainDateTimeLike | string): Temporal.Instant[];
toString(): string;
toJSON(): string;
readonly [Symbol.toStringTag]: 'Temporal.TimeZone';
}

export type PlainYearMonthLike = {
Expand Down Expand Up @@ -1329,6 +1337,7 @@ export namespace Temporal {
toJSON(): string;
toString(options?: ShowCalendarOption): string;
valueOf(): never;
readonly [Symbol.toStringTag]: 'Temporal.PlainYearMonth';
}

export type ZonedDateTimeLike = {
Expand Down Expand Up @@ -1492,6 +1501,7 @@ export namespace Temporal {
toJSON(): string;
toString(options?: ZonedDateTimeToStringOptions): string;
valueOf(): never;
readonly [Symbol.toStringTag]: 'Temporal.ZonedDateTime';
}

/**
Expand All @@ -1500,7 +1510,7 @@ export namespace Temporal {
*
* See https://tc39.es/proposal-temporal/docs/now.html for more details.
*/
export namespace Now {
export const Now: {
/**
* Get the exact system date and time as a `Temporal.Instant`.
*
Expand All @@ -1513,7 +1523,7 @@ export namespace Temporal {
* exact time in a specific time zone, use `Temporal.Now.zonedDateTimeISO`
* or `Temporal.Now.zonedDateTime`.
* */
export function instant(): Temporal.Instant;
instant: () => Temporal.Instant;

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

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

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

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

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

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

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

/**
* Get the environment's current time zone.
Expand All @@ -1646,8 +1647,10 @@ export namespace Temporal {
* named
* {@link https://en.wikipedia.org/wiki/List_of_tz_database_time_zones|IANA time zone}.
*/
export function timeZone(): Temporal.TimeZone;
}
timeZone: () => Temporal.TimeZone;

readonly [Symbol.toStringTag]: 'Temporal.Now';
};
}

declare namespace IntlPolyfill {
Expand Down
1 change: 1 addition & 0 deletions lib/calendar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ export class Calendar implements Temporal.Calendar {
static from(item) {
return ES.ToTemporalCalendar(item);
}
[Symbol.toStringTag]!: 'Temporal.Calendar';
}

MakeIntrinsicClass(Calendar, 'Temporal.Calendar');
Expand Down
1 change: 1 addition & 0 deletions lib/duration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,7 @@ export class Duration implements Temporal.Duration {
ns2 = ES.TotalDurationNanoseconds(d2, h2, min2, s2, ms2, µs2, ns2, shift2);
return ES.ComparisonResult(ns1.minus(ns2).toJSNumber());
}
[Symbol.toStringTag]!: 'Temporal.Duration';
}

MakeIntrinsicClass(Duration, 'Temporal.Duration');
1 change: 1 addition & 0 deletions lib/instant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ export class Instant implements Temporal.Instant {
if (bigInt(one).greater(two)) return 1;
return 0;
}
[Symbol.toStringTag]!: 'Temporal.Instant';
}

MakeIntrinsicClass(Instant, 'Temporal.Instant');
Expand Down
3 changes: 2 additions & 1 deletion lib/now.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ export const Now: typeof Temporal.Now = {
plainTimeISO,
timeZone,
zonedDateTime,
zonedDateTimeISO
zonedDateTimeISO,
[Symbol.toStringTag]: 'Temporal.Now'
};
Object.defineProperty(Now, Symbol.toStringTag, {
value: 'Temporal.Now',
Expand Down
1 change: 1 addition & 0 deletions lib/plaindate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,7 @@ export class PlainDate implements Temporal.PlainDate {
GetSlot(two, ISO_DAY)
);
}
[Symbol.toStringTag]!: 'Temporal.PlainDate';
}

MakeIntrinsicClass(PlainDate, 'Temporal.PlainDate');
1 change: 1 addition & 0 deletions lib/plaindatetime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -701,6 +701,7 @@ export class PlainDateTime implements Temporal.PlainDateTime {
}
return 0;
}
[Symbol.toStringTag]!: 'Temporal.PlainDateTime';
}

MakeIntrinsicClass(PlainDateTime, 'Temporal.PlainDateTime');
1 change: 1 addition & 0 deletions lib/plainmonthday.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ export class PlainMonthDay implements Temporal.PlainMonthDay {
}
return ES.ToTemporalMonthDay(item, options);
}
[Symbol.toStringTag]!: 'Temporal.PlainMonthDay';
}

MakeIntrinsicClass(PlainMonthDay, 'Temporal.PlainMonthDay');
1 change: 1 addition & 0 deletions lib/plaintime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,7 @@ export class PlainTime implements Temporal.PlainTime {
}
return 0;
}
[Symbol.toStringTag]!: 'Temporal.PlainTime';
}

MakeIntrinsicClass(PlainTime, 'Temporal.PlainTime');
1 change: 1 addition & 0 deletions lib/plainyearmonth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,7 @@ export class PlainYearMonth implements Temporal.PlainYearMonth {
GetSlot(two, ISO_DAY)
);
}
[Symbol.toStringTag]!: 'Temporal.PlainYearMonth';
}

MakeIntrinsicClass(PlainYearMonth, 'Temporal.PlainYearMonth');
1 change: 1 addition & 0 deletions lib/timezone.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ export class TimeZone implements Temporal.TimeZone {
static from(item) {
return ES.ToTemporalTimeZone(item);
}
[Symbol.toStringTag]!: 'Temporal.TimeZone';
}

MakeIntrinsicClass(TimeZone, 'Temporal.TimeZone');
Expand Down
1 change: 1 addition & 0 deletions lib/zoneddatetime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -771,6 +771,7 @@ export class ZonedDateTime implements Temporal.ZonedDateTime {
if (bigInt(ns1).greater(ns2)) return 1;
return 0;
}
[Symbol.toStringTag]!: 'Temporal.ZonedDateTime';
}

MakeIntrinsicClass(ZonedDateTime, 'Temporal.ZonedDateTime');
Expand Down

0 comments on commit 41ab6bc

Please sign in to comment.