Skip to content

Commit

Permalink
Use typesVersions to check existence of Intl.LocalesArgument type
Browse files Browse the repository at this point in the history
  • Loading branch information
lionel-rowe committed Mar 2, 2023
1 parent 6e689dc commit 6516a2e
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 36 deletions.
17 changes: 17 additions & 0 deletions index-lt-4.7.4.d.ts
@@ -0,0 +1,17 @@
export * from './index';

declare global {
namespace Intl {
/**
* The locale or locales to use
*
* See [MDN - Intl - locales
* argument](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl#locales_argument)
*/
type LocalesArgument =
| UnicodeBCP47LocaleIdentifier
| globalThis.Intl.Locale
| readonly (UnicodeBCP47LocaleIdentifier | globalThis.Intl.Locale)[]
| undefined;
}
}
47 changes: 11 additions & 36 deletions index.d.ts
Expand Up @@ -548,7 +548,7 @@ export namespace Temporal {
subtract(other: Temporal.Duration | DurationLike | string, options?: DurationArithmeticOptions): Temporal.Duration;
round(roundTo: DurationRoundTo): Temporal.Duration;
total(totalOf: DurationTotalOf): number;
toLocaleString(locales?: Intl.LocalesArgument, options?: Intl.DateTimeFormatOptions): string;
toLocaleString(locales?: globalThis.Intl.LocalesArgument, options?: Intl.DateTimeFormatOptions): string;
toJSON(): string;
toString(options?: ToStringPrecisionOptions): string;
valueOf(): never;
Expand Down Expand Up @@ -601,7 +601,7 @@ export namespace Temporal {
): Temporal.Instant;
toZonedDateTime(calendarAndTimeZone: { timeZone: TimeZoneLike; calendar: CalendarLike }): Temporal.ZonedDateTime;
toZonedDateTimeISO(tzLike: TimeZoneLike): Temporal.ZonedDateTime;
toLocaleString(locales?: Intl.LocalesArgument, options?: Intl.DateTimeFormatOptions): string;
toLocaleString(locales?: globalThis.Intl.LocalesArgument, options?: Intl.DateTimeFormatOptions): string;
toJSON(): string;
toString(options?: InstantToStringOptions): string;
valueOf(): never;
Expand Down Expand Up @@ -836,7 +836,7 @@ export namespace Temporal {
toPlainYearMonth(): Temporal.PlainYearMonth;
toPlainMonthDay(): Temporal.PlainMonthDay;
getISOFields(): PlainDateISOFields;
toLocaleString(locales?: Intl.LocalesArgument, options?: Intl.DateTimeFormatOptions): string;
toLocaleString(locales?: globalThis.Intl.LocalesArgument, options?: Intl.DateTimeFormatOptions): string;
toJSON(): string;
toString(options?: ShowCalendarOption): string;
valueOf(): never;
Expand Down Expand Up @@ -955,7 +955,7 @@ export namespace Temporal {
toPlainMonthDay(): Temporal.PlainMonthDay;
toPlainTime(): Temporal.PlainTime;
getISOFields(): PlainDateTimeISOFields;
toLocaleString(locales?: Intl.LocalesArgument, options?: Intl.DateTimeFormatOptions): string;
toLocaleString(locales?: globalThis.Intl.LocalesArgument, options?: Intl.DateTimeFormatOptions): string;
toJSON(): string;
toString(options?: CalendarTypeToStringOptions): string;
valueOf(): never;
Expand Down Expand Up @@ -992,7 +992,7 @@ export namespace Temporal {
with(monthDayLike: PlainMonthDayLike, options?: AssignmentOptions): Temporal.PlainMonthDay;
toPlainDate(year: { year: number }): Temporal.PlainDate;
getISOFields(): PlainDateISOFields;
toLocaleString(locales?: Intl.LocalesArgument, options?: Intl.DateTimeFormatOptions): string;
toLocaleString(locales?: globalThis.Intl.LocalesArgument, options?: Intl.DateTimeFormatOptions): string;
toJSON(): string;
toString(options?: ShowCalendarOption): string;
valueOf(): never;
Expand Down Expand Up @@ -1085,7 +1085,7 @@ export namespace Temporal {
plainDate: Temporal.PlainDate | PlainDateLike | string;
}): Temporal.ZonedDateTime;
getISOFields(): PlainTimeISOFields;
toLocaleString(locales?: Intl.LocalesArgument, options?: Intl.DateTimeFormatOptions): string;
toLocaleString(locales?: globalThis.Intl.LocalesArgument, options?: Intl.DateTimeFormatOptions): string;
toJSON(): string;
toString(options?: ToStringPrecisionOptions): string;
valueOf(): never;
Expand Down Expand Up @@ -1199,7 +1199,7 @@ export namespace Temporal {
): Temporal.Duration;
toPlainDate(day: { day: number }): Temporal.PlainDate;
getISOFields(): PlainDateISOFields;
toLocaleString(locales?: Intl.LocalesArgument, options?: Intl.DateTimeFormatOptions): string;
toLocaleString(locales?: globalThis.Intl.LocalesArgument, options?: Intl.DateTimeFormatOptions): string;
toJSON(): string;
toString(options?: ShowCalendarOption): string;
valueOf(): never;
Expand Down Expand Up @@ -1312,7 +1312,7 @@ export namespace Temporal {
toPlainMonthDay(): Temporal.PlainMonthDay;
toPlainTime(): Temporal.PlainTime;
getISOFields(): ZonedDateTimeISOFields;
toLocaleString(locales?: Intl.LocalesArgument, options?: Intl.DateTimeFormatOptions): string;
toLocaleString(locales?: globalThis.Intl.LocalesArgument, options?: Intl.DateTimeFormatOptions): string;
toJSON(): string;
toString(options?: ZonedDateTimeToStringOptions): string;
valueOf(): never;
Expand Down Expand Up @@ -1537,41 +1537,16 @@ declare namespace Intl {
* Creates `Intl.DateTimeFormat` objects that enable language-sensitive
* date and time formatting.
*/
new (locales?: Intl.LocalesArgument, options?: DateTimeFormatOptions): DateTimeFormat;
(locales?: Intl.LocalesArgument, options?: DateTimeFormatOptions): DateTimeFormat;
new (locales?: globalThis.Intl.LocalesArgument, options?: DateTimeFormatOptions): DateTimeFormat;
(locales?: globalThis.Intl.LocalesArgument, options?: DateTimeFormatOptions): DateTimeFormat;

/**
* Get an array containing those of the provided locales that are supported
* in date and time formatting without having to fall back to the runtime's
* default locale.
*/
supportedLocalesOf(locales: Intl.LocalesArgument, options?: DateTimeFormatOptions): string[];
supportedLocalesOf(locales: globalThis.Intl.LocalesArgument, options?: DateTimeFormatOptions): string[];
};

// TODO: remove UnicodeBCP47LocaleIdentifier and LocalesArgument once TS lib declarations for these in widespread use

/**
* A string that is a valid [Unicode BCP 47 Locale
* Identifier](https://unicode.org/reports/tr35/#Unicode_locale_identifier).
*
* For example: "fa", "es-MX", "zh-Hant-TW".
*
* See [MDN - Intl - locales
* argument](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl#locales_argument).
*/
type UnicodeBCP47LocaleIdentifier = string;

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

export { Intl as Intl };
Expand Down
7 changes: 7 additions & 0 deletions package.json
Expand Up @@ -23,6 +23,13 @@
]
},
"types": "./index.d.ts",
"typesVersions": {
"<4.7.4": {
"index.d.ts": [
"index-lt-4.7.4.d.ts"
]
}
},
"scripts": {
"test": "npm run build && node --no-warnings --experimental-modules --experimental-specifier-resolution=node --icu-data-dir node_modules/full-icu --loader ./test/resolve.source.mjs ./test/all.mjs",
"test262": "TEST262=1 npm run build && node runtest262.mjs \"$@\"",
Expand Down

0 comments on commit 6516a2e

Please sign in to comment.