Skip to content

intl.d.ts: cleanup, add missing features, fix library discrepancies #58084

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

Open
wants to merge 61 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
4cce807
Remaining registry interfaces to {key: never}
Renegade334 Feb 10, 2024
a6b7bad
Intl.DateTimeFormat: fix options
Renegade334 Feb 12, 2024
5265cbc
DateTimeFormat functions do not accept BigInts
Renegade334 Feb 12, 2024
fea424d
Intl.CollatorOptions: remove string union of valid collations
Renegade334 Feb 12, 2024
c676adf
Intl.Collator: fix options
Renegade334 Feb 12, 2024
2d8de76
Update locale methods on primitive prototypes
Renegade334 Mar 2, 2024
8f78556
Update baselines
Renegade334 Mar 2, 2024
3166c84
Merge branch 'main' into intl-cleanup
Renegade334 Apr 1, 2024
1961da6
Intl.PluralRules: fix options
Renegade334 Apr 2, 2024
aaf1758
Intl.PluralRules: add #selectRange()
Renegade334 Apr 2, 2024
27bbc61
Intl.DateTimeFormatOptions: union type deduplication
Renegade334 Apr 2, 2024
50d6708
Intl.CollatorOptions: union type deduplication
Renegade334 Apr 2, 2024
f5204b9
Intl.NumberFormatOptions: union type deduplication
Renegade334 Apr 2, 2024
d8363b4
Intl.Locale: refactor
Renegade334 Apr 2, 2024
2cb5dee
Intl.Locale: simplify docblocks
Renegade334 Apr 2, 2024
d68c136
Remove primitive alias UnicodeBCP47LocaleIdentifier
Renegade334 Apr 2, 2024
4c84f0e
Add missing prototypes on Intl constructor interfaces
Renegade334 Apr 2, 2024
0ff12bd
Update baselines
Renegade334 Apr 2, 2024
7354ab0
Further primitive prototype locale method updates
Renegade334 Apr 2, 2024
7871f1e
Intl.RelativeTimeFormat: fixes
Renegade334 Apr 2, 2024
19d70ce
Intl.DisplayNames: fixes
Renegade334 Apr 2, 2024
fda90ca
Intl.ListFormat: fixes
Renegade334 Apr 2, 2024
ff38aff
Intl.getCanonicalLocales: add es2020 override
Renegade334 Apr 2, 2024
cb957d1
Intl.supportedLocalesOf: move to es2023
Renegade334 Apr 2, 2024
b1cf424
Intl.Segmenter: fixes
Renegade334 Apr 2, 2024
daa14b8
Declare constructors with `var` rather than `const`
Renegade334 Apr 2, 2024
165b31c
`locales` arguments
Renegade334 Apr 2, 2024
8cf8f28
Update tests/baselines
Renegade334 Apr 3, 2024
a7f690b
Merge branch 'main' into intl-cleanup
Renegade334 Apr 3, 2024
ae033d3
supportedLocalesOf: separate options interface
Renegade334 Apr 3, 2024
e5c29dd
Fix fourslash test
Renegade334 Apr 3, 2024
9624605
Docblocks
Renegade334 Apr 3, 2024
1209aee
Whitespace
Renegade334 Apr 3, 2024
ab7cfc1
Intl.Locale: optional properties
Renegade334 Apr 4, 2024
b3dd379
DateTimeFormat docblocks
Renegade334 Apr 4, 2024
edf8ae6
Add/consolidate conformance tests
Renegade334 Apr 4, 2024
dd2e100
Merge branch 'main' into intl-cleanup
Renegade334 Apr 5, 2024
62be4e9
Fix indentation
Renegade334 Apr 5, 2024
ffe0b99
Remove leftover testfile
Renegade334 Apr 5, 2024
3459af2
Remove leftover baselines
Renegade334 Apr 5, 2024
3d631ca
Intl.PluralRules: constructor cannot be invoked without `new`
Renegade334 Apr 8, 2024
7827f33
Merge branch 'main' into intl-cleanup
Renegade334 Apr 8, 2024
9d2741c
Revert Intl.Locale.prototype.language type
Renegade334 Apr 10, 2024
d7dc3e2
Merge branch 'main' into intl-cleanup
Renegade334 Apr 10, 2024
4e06b5e
Docblocks: BCP47
Renegade334 Apr 14, 2024
ac84ff5
Merge branch 'main' into intl-cleanup
Renegade334 Apr 14, 2024
30bc011
Intl.Locale: readonly properties
Renegade334 Apr 16, 2024
5c8b793
LocaleMatcherAlgorithm
Renegade334 Apr 18, 2024
0c035e3
Merge branch 'main' into intl-cleanup
Renegade334 Apr 18, 2024
1ddd414
Merge branch 'main' into intl-cleanup
Renegade334 Apr 26, 2024
cb3a856
Merge branch 'main' into intl-cleanup
Renegade334 May 12, 2024
b6acf0f
Docblocks: es5
Renegade334 May 13, 2024
897fc6d
Merge branch 'main' into intl-cleanup
Renegade334 May 13, 2024
0cd1814
Whitespace
Renegade334 May 13, 2024
31d8a82
[??] Array.prototype.toLocaleString: infer options type
Renegade334 May 13, 2024
9e37c30
Merge branch 'main' into intl-cleanup
Renegade334 May 28, 2024
6fa9cf2
Merge branch 'main' into intl-cleanup
Renegade334 Jun 5, 2024
193ea18
Change registry type convention
Renegade334 Jun 11, 2024
c08b13c
Remove redundant test
Renegade334 Jun 11, 2024
86d0f1a
Merge branch 'main' into intl-cleanup
Renegade334 Jun 11, 2024
596edb5
revert 31d8a82: "[??] Array.prototype.toLocaleString: infer options t…
Renegade334 Jun 11, 2024
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
1 change: 1 addition & 0 deletions src/compiler/commandLineParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ const libEntries: [string, string][] = [
["es2019.string", "lib.es2019.string.d.ts"],
["es2019.symbol", "lib.es2019.symbol.d.ts"],
["es2019.intl", "lib.es2019.intl.d.ts"],
["es2020.array", "lib.es2020.array.d.ts"],
["es2020.bigint", "lib.es2020.bigint.d.ts"],
["es2020.date", "lib.es2020.date.d.ts"],
["es2020.promise", "lib.es2020.promise.d.ts"],
Expand Down
104 changes: 93 additions & 11 deletions src/lib/es2015.core.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,13 @@ interface Array<T> {
*/
copyWithin(target: number, start: number, end?: number): this;

toLocaleString(locales: string | string[], options?: Intl.NumberFormatOptions & Intl.DateTimeFormatOptions): string;
/**
* Returns a string representation of an array.
* Each element is converted to a string using its `toLocaleString` method, then concatenated using the list separator of the current locale.
* @param locales Passed as the `locales` parameter to each array element's `toLocaleString` method.
* @param options Passed as the `options` parameter to each array element's `toLocaleString` method.
*/
toLocaleString(locales?: string | readonly string[], options?: object): string;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See notes towards the bottom of the PR description for discussion regarding the type of options here.

I'm ambivalent towards the change, but thought it would be worth proposing.

}

interface ArrayConstructor {
Expand Down Expand Up @@ -345,7 +351,13 @@ interface ReadonlyArray<T> {
*/
findIndex(predicate: (value: T, index: number, obj: readonly T[]) => unknown, thisArg?: any): number;

toLocaleString(locales: string | string[], options?: Intl.NumberFormatOptions & Intl.DateTimeFormatOptions): string;
/**
* Returns a string representation of an array.
* Each element is converted to a string using its `toLocaleString` method, then concatenated using the list separator of the current locale.
* @param locales Passed as the `locales` parameter to each array element's `toLocaleString` method.
* @param options Passed as the `options` parameter to each array element's `toLocaleString` method.
*/
toLocaleString(locales?: string | readonly string[], options?: object): string;
}

interface RegExp {
Expand Down Expand Up @@ -437,6 +449,22 @@ interface String {
*/
startsWith(searchString: string, position?: number): boolean;

/**
* Converts all alphabetic characters to lowercase, using locale-sensitive case mappings.
* @param locales A Unicode BCP 47 locale identifier, or list of identifiers, specifying the preferred locale to use for the conversion.
* This method does not perform locale matching; instead, it always selects the first supported locale.
* If omitted, the default locale is used.
*/
toLocaleLowerCase(locales?: string | readonly string[]): string;

/**
* Converts all alphabetic characters to uppercase, using locale-sensitive case mappings.
* @param locales A Unicode BCP 47 locale identifier, or list of identifiers, specifying the preferred locale to use for the conversion.
* This method does not perform locale matching; instead, it always selects the first supported locale.
* If omitted, the default locale is used.
*/
toLocaleUpperCase(locales?: string | readonly string[]): string;

/**
* Returns an `<a>` HTML anchor element and sets the name attribute to the text value
* @deprecated A legacy feature for browser compatibility
Expand Down Expand Up @@ -543,37 +571,91 @@ interface StringConstructor {
}

interface Int8Array {
toLocaleString(locales: string | string[], options?: Intl.NumberFormatOptions): string;
/**
* Returns a string representation of a TypedArray.
* Each element is converted to a string using its `toLocaleString` method, then concatenated using the list separator of the current locale.
* @param locales A Unicode BCP 47 locale identifier, or list of identifiers, specifying the preferred locale to use for the conversion. If omitted, the default locale is used.
* @param options Corresponds to the `options` parameter of the `Intl.NumberFormat` constructor.
*/
toLocaleString(locales?: string | readonly string[], options?: Intl.NumberFormatOptions): string;
}

interface Uint8Array {
toLocaleString(locales: string | string[], options?: Intl.NumberFormatOptions): string;
/**
* Returns a string representation of a TypedArray.
* Each element is converted to a string using its `toLocaleString` method, then concatenated using the list separator of the current locale.
* @param locales A Unicode BCP 47 locale identifier, or list of identifiers, specifying the preferred locale to use for the conversion. If omitted, the default locale is used.
* @param options Corresponds to the `options` parameter of the `Intl.NumberFormat` constructor.
*/
toLocaleString(locales?: string | readonly string[], options?: Intl.NumberFormatOptions): string;
}

interface Uint8ClampedArray {
toLocaleString(locales: string | string[], options?: Intl.NumberFormatOptions): string;
/**
* Returns a string representation of a TypedArray.
* Each element is converted to a string using its `toLocaleString` method, then concatenated using the list separator of the current locale.
* @param locales A Unicode BCP 47 locale identifier, or list of identifiers, specifying the preferred locale to use for the conversion. If omitted, the default locale is used.
* @param options Corresponds to the `options` parameter of the `Intl.NumberFormat` constructor.
*/
toLocaleString(locales?: string | readonly string[], options?: Intl.NumberFormatOptions): string;
}

interface Int16Array {
toLocaleString(locales: string | string[], options?: Intl.NumberFormatOptions): string;
/**
* Returns a string representation of a TypedArray.
* Each element is converted to a string using its `toLocaleString` method, then concatenated using the list separator of the current locale.
* @param locales A Unicode BCP 47 locale identifier, or list of identifiers, specifying the preferred locale to use for the conversion. If omitted, the default locale is used.
* @param options Corresponds to the `options` parameter of the `Intl.NumberFormat` constructor.
*/
toLocaleString(locales?: string | readonly string[], options?: Intl.NumberFormatOptions): string;
}

interface Uint16Array {
toLocaleString(locales: string | string[], options?: Intl.NumberFormatOptions): string;
/**
* Returns a string representation of a TypedArray.
* Each element is converted to a string using its `toLocaleString` method, then concatenated using the list separator of the current locale.
* @param locales A Unicode BCP 47 locale identifier, or list of identifiers, specifying the preferred locale to use for the conversion. If omitted, the default locale is used.
* @param options Corresponds to the `options` parameter of the `Intl.NumberFormat` constructor.
*/
toLocaleString(locales?: string | readonly string[], options?: Intl.NumberFormatOptions): string;
}

interface Int32Array {
toLocaleString(locales: string | string[], options?: Intl.NumberFormatOptions): string;
/**
* Returns a string representation of a TypedArray.
* Each element is converted to a string using its `toLocaleString` method, then concatenated using the list separator of the current locale.
* @param locales A Unicode BCP 47 locale identifier, or list of identifiers, specifying the preferred locale to use for the conversion. If omitted, the default locale is used.
* @param options Corresponds to the `options` parameter of the `Intl.NumberFormat` constructor.
*/
toLocaleString(locales?: string | readonly string[], options?: Intl.NumberFormatOptions): string;
}

interface Uint32Array {
toLocaleString(locales: string | string[], options?: Intl.NumberFormatOptions): string;
/**
* Returns a string representation of a TypedArray.
* Each element is converted to a string using its `toLocaleString` method, then concatenated using the list separator of the current locale.
* @param locales A Unicode BCP 47 locale identifier, or list of identifiers, specifying the preferred locale to use for the conversion. If omitted, the default locale is used.
* @param options Corresponds to the `options` parameter of the `Intl.NumberFormat` constructor.
*/
toLocaleString(locales?: string | readonly string[], options?: Intl.NumberFormatOptions): string;
}

interface Float32Array {
toLocaleString(locales: string | string[], options?: Intl.NumberFormatOptions): string;
/**
* Returns a string representation of a TypedArray.
* Each element is converted to a string using its `toLocaleString` method, then concatenated using the list separator of the current locale.
* @param locales A Unicode BCP 47 locale identifier, or list of identifiers, specifying the preferred locale to use for the conversion. If omitted, the default locale is used.
* @param options Corresponds to the `options` parameter of the `Intl.NumberFormat` constructor.
*/
toLocaleString(locales?: string | readonly string[], options?: Intl.NumberFormatOptions): string;
}

interface Float64Array {
toLocaleString(locales: string | string[], options?: Intl.NumberFormatOptions): string;
/**
* Returns a string representation of a TypedArray.
* Each element is converted to a string using its `toLocaleString` method, then concatenated using the list separator of the current locale.
* @param locales A Unicode BCP 47 locale identifier, or list of identifiers, specifying the preferred locale to use for the conversion. If omitted, the default locale is used.
* @param options Corresponds to the `options` parameter of the `Intl.NumberFormat` constructor.
*/
toLocaleString(locales?: string | readonly string[], options?: Intl.NumberFormatOptions): string;
}
13 changes: 4 additions & 9 deletions src/lib/es2016.intl.d.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
declare namespace Intl {
/**
* The `Intl.getCanonicalLocales()` method returns an array containing
* the canonical locale names. Duplicates will be omitted and elements
* will be validated as structurally valid language tags.
*
* [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/getCanonicalLocales)
*
* @param locale A list of String values for which to get the canonical locale names
* @returns An array containing the canonical and validated locale names.
* Takes a list of locale identifiers, and returns a deduplicated list of their canonical names.
* Structurally invalid identifiers will cause an error to be thrown.
* @param locales A Unicode BCP 47 locale identifier, or list of identifiers.
*/
function getCanonicalLocales(locale?: string | readonly string[]): string[];
function getCanonicalLocales(locales?: string | readonly string[]): string[];
}
30 changes: 17 additions & 13 deletions src/lib/es2017.intl.d.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,30 @@
declare namespace Intl {
interface DateTimeFormatPartTypesRegistry {
day: any;
dayPeriod: any;
era: any;
hour: any;
literal: any;
minute: any;
month: any;
second: any;
timeZoneName: any;
weekday: any;
year: any;
day: "day";
dayPeriod: "dayPeriod";
era: "era";
hour: "hour";
literal: "literal";
minute: "minute";
month: "month";
second: "second";
timeZoneName: "timeZoneName";
weekday: "weekday";
year: "year";
}

type DateTimeFormatPartTypes = keyof DateTimeFormatPartTypesRegistry;
type DateTimeFormatPartTypes = DateTimeFormatPartTypesRegistry[keyof DateTimeFormatPartTypesRegistry];

interface DateTimeFormatPart {
type: DateTimeFormatPartTypes;
value: string;
}

interface DateTimeFormat {
/**
* Formats a date as a string, according to the selected locale and formatting options,
* and returns the result as a list of locale-specific string tokens.
* @param date A `Date` object or timestamp. If undefined, defaults to the value of `Date.now()`.
*/
formatToParts(date?: Date | number): DateTimeFormatPart[];
}
}
72 changes: 49 additions & 23 deletions src/lib/es2018.intl.d.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
declare namespace Intl {
// http://cldr.unicode.org/index/cldr-spec/plural-rules#TOC-Determining-Plural-Categories
type LDMLPluralRule = "zero" | "one" | "two" | "few" | "many" | "other";
type PluralRuleType = "cardinal" | "ordinal";

interface PluralRulesOptions {
localeMatcher?: "lookup" | "best fit" | undefined;
localeMatcher?: LocaleMatcherAlgorithm | undefined;
type?: PluralRuleType | undefined;
minimumIntegerDigits?: number | undefined;
minimumFractionDigits?: number | undefined;
Expand All @@ -18,48 +17,75 @@ declare namespace Intl {
pluralCategories: LDMLPluralRule[];
type: PluralRuleType;
minimumIntegerDigits: number;
minimumFractionDigits: number;
maximumFractionDigits: number;
minimumFractionDigits?: number;
maximumFractionDigits?: number;
Comment on lines +20 to +21
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Intentionally optional.

minimumSignificantDigits?: number;
maximumSignificantDigits?: number;
}

interface PluralRules {
resolvedOptions(): ResolvedPluralRulesOptions;
/**
* Returns the plural rule identifier for the given number, according to the selected locale and parsing options.
* @param n The number to parse.
*/
select(n: number): LDMLPluralRule;

/** Returns the locale and options computed during initialization of this `PluralRules` instance. */
resolvedOptions(): ResolvedPluralRulesOptions;
}

interface PluralRulesConstructor {
new (locales?: string | readonly string[], options?: PluralRulesOptions): PluralRules;
(locales?: string | readonly string[], options?: PluralRulesOptions): PluralRules;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cannot be invoked without new.

supportedLocalesOf(locales: string | readonly string[], options?: { localeMatcher?: "lookup" | "best fit"; }): string[];
readonly prototype: PluralRules;

/**
* Takes a list of locale identifiers, and returns the subset of identifiers that are supported by the current implementation of `PluralRules`.
* If none of the provided locales are supported, an empty array is returned.
* @param locales A Unicode BCP 47 locale identifier, or list of identifiers.
* @param options Options for the locale matching algorithm.
*/
supportedLocalesOf(locales?: string | readonly string[], options?: SupportedLocalesOptions): string[];
}

const PluralRules: PluralRulesConstructor;
var PluralRules: PluralRulesConstructor;

interface NumberFormatPartTypeRegistry {
literal: never;
nan: never;
infinity: never;
percent: never;
integer: never;
group: never;
decimal: never;
fraction: never;
plusSign: never;
minusSign: never;
percentSign: never;
currency: never;
literal: "literal";
nan: "nan";
infinity: "infinity";
percent: "percent";
integer: "integer";
group: "group";
decimal: "decimal";
fraction: "fraction";
plusSign: "plusSign";
minusSign: "minusSign";
percentSign: "percentSign";
currency: "currency";
}

type NumberFormatPartTypes = keyof NumberFormatPartTypeRegistry;
type NumberFormatPartTypes = NumberFormatPartTypeRegistry[keyof NumberFormatPartTypeRegistry];

interface NumberFormatPart {
type: NumberFormatPartTypes;
value: string;
}

interface NumberFormat {
formatToParts(number?: number | bigint): NumberFormatPart[];
/**
* Formats a number as a string, according to the selected locale and formatting options,
* and returns the result as a list of locale-specific string tokens.
* @param value The value to be formatted.
*/
formatToParts(value?: number): NumberFormatPart[];
}

type DateTimeFormatOptionsHourCycle = "h11" | "h12" | "h23" | "h24";

interface DateTimeFormatOptions {
hourCycle?: DateTimeFormatOptionsHourCycle | undefined;
}

interface ResolvedDateTimeFormatOptions {
hourCycle?: DateTimeFormatOptionsHourCycle;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Intentionally optional.

}
}
2 changes: 1 addition & 1 deletion src/lib/es2019.intl.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
declare namespace Intl {
interface DateTimeFormatPartTypesRegistry {
unknown: never;
unknown: "unknown";
}
}
Loading