Skip to content

Commit fbe2219

Browse files
CopilotRyanCavanaughjakebailey
authored
Add approximatelySign to NumberFormatRangePartTypeRegistry for ES2023 (#62013)
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: RyanCavanaugh <6685088+RyanCavanaugh@users.noreply.github.com> Co-authored-by: jakebailey <5341706+jakebailey@users.noreply.github.com>
1 parent d3ce3cf commit fbe2219

File tree

5 files changed

+204
-8
lines changed

5 files changed

+204
-8
lines changed

src/lib/es2023.intl.d.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ declare namespace Intl {
99
negative: never;
1010
}
1111

12+
interface NumberFormatRangePartTypeRegistry extends NumberFormatPartTypeRegistry {
13+
approximatelySign: never;
14+
}
15+
16+
type NumberFormatRangePartTypes = keyof NumberFormatRangePartTypeRegistry;
17+
1218
interface NumberFormatOptions {
1319
roundingPriority?: "auto" | "morePrecision" | "lessPrecision" | undefined;
1420
roundingIncrement?: 1 | 2 | 5 | 10 | 20 | 25 | 50 | 100 | 200 | 250 | 500 | 1000 | 2000 | 2500 | 5000 | undefined;
@@ -23,7 +29,9 @@ declare namespace Intl {
2329
trailingZeroDisplay: "auto" | "stripIfInteger";
2430
}
2531

26-
interface NumberRangeFormatPart extends NumberFormatPart {
32+
interface NumberRangeFormatPart {
33+
type: NumberFormatRangePartTypes;
34+
value: string;
2735
source: "startRange" | "endRange" | "shared";
2836
}
2937

tests/baselines/reference/intlNumberFormatES2023.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,19 @@ new Intl.NumberFormat('en-GB').formatRangeToParts('123E-4', '567E8');
3131
new Intl.NumberFormat('en-GB').format('Infinity');
3232
new Intl.NumberFormat('en-GB').format('-Infinity');
3333
new Intl.NumberFormat('en-GB').format('+Infinity');
34+
35+
// Test approximatelySign part type
36+
const nf = new Intl.NumberFormat("en-US", {
37+
style: "currency",
38+
currency: "EUR",
39+
maximumFractionDigits: 0,
40+
});
41+
42+
const filtered = nf
43+
.formatRangeToParts(100, 100)
44+
.filter((part) => part.type !== "approximatelySign")
45+
.map((part) => part.value)
46+
.join("");
3447

3548

3649
//// [intlNumberFormatES2023.js]
@@ -59,3 +72,14 @@ new Intl.NumberFormat('en-GB').formatRangeToParts('123E-4', '567E8');
5972
new Intl.NumberFormat('en-GB').format('Infinity');
6073
new Intl.NumberFormat('en-GB').format('-Infinity');
6174
new Intl.NumberFormat('en-GB').format('+Infinity');
75+
// Test approximatelySign part type
76+
const nf = new Intl.NumberFormat("en-US", {
77+
style: "currency",
78+
currency: "EUR",
79+
maximumFractionDigits: 0,
80+
});
81+
const filtered = nf
82+
.formatRangeToParts(100, 100)
83+
.filter((part) => part.type !== "approximatelySign")
84+
.map((part) => part.value)
85+
.join("");

tests/baselines/reference/intlNumberFormatES2023.symbols

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,3 +130,49 @@ new Intl.NumberFormat('en-GB').format('+Infinity');
130130
>NumberFormat : Symbol(Intl.NumberFormat, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2018.intl.d.ts, --, --), Decl(lib.es2020.bigint.d.ts, --, --), Decl(lib.es2023.intl.d.ts, --, --))
131131
>format : Symbol(Intl.NumberFormat.format, Decl(lib.es5.d.ts, --, --), Decl(lib.es2020.bigint.d.ts, --, --), Decl(lib.es2023.intl.d.ts, --, --))
132132

133+
// Test approximatelySign part type
134+
const nf = new Intl.NumberFormat("en-US", {
135+
>nf : Symbol(nf, Decl(intlNumberFormatES2023.ts, 32, 5))
136+
>Intl.NumberFormat : Symbol(Intl.NumberFormat, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2018.intl.d.ts, --, --), Decl(lib.es2020.bigint.d.ts, --, --), Decl(lib.es2023.intl.d.ts, --, --))
137+
>Intl : Symbol(Intl, Decl(lib.es5.d.ts, --, --), Decl(lib.es2016.intl.d.ts, --, --), Decl(lib.es2017.intl.d.ts, --, --), Decl(lib.es2018.intl.d.ts, --, --), Decl(lib.es2019.intl.d.ts, --, --) ... and 5 more)
138+
>NumberFormat : Symbol(Intl.NumberFormat, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2018.intl.d.ts, --, --), Decl(lib.es2020.bigint.d.ts, --, --), Decl(lib.es2023.intl.d.ts, --, --))
139+
140+
style: "currency",
141+
>style : Symbol(style, Decl(intlNumberFormatES2023.ts, 32, 43))
142+
143+
currency: "EUR",
144+
>currency : Symbol(currency, Decl(intlNumberFormatES2023.ts, 33, 20))
145+
146+
maximumFractionDigits: 0,
147+
>maximumFractionDigits : Symbol(maximumFractionDigits, Decl(intlNumberFormatES2023.ts, 34, 18))
148+
149+
});
150+
151+
const filtered = nf
152+
>filtered : Symbol(filtered, Decl(intlNumberFormatES2023.ts, 38, 5))
153+
>nf .formatRangeToParts(100, 100) .filter((part) => part.type !== "approximatelySign") .map((part) => part.value) .join : Symbol(Array.join, Decl(lib.es5.d.ts, --, --))
154+
>nf .formatRangeToParts(100, 100) .filter((part) => part.type !== "approximatelySign") .map : Symbol(Array.map, Decl(lib.es5.d.ts, --, --))
155+
>nf .formatRangeToParts(100, 100) .filter : Symbol(Array.filter, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
156+
>nf .formatRangeToParts : Symbol(Intl.NumberFormat.formatRangeToParts, Decl(lib.es2023.intl.d.ts, --, --))
157+
>nf : Symbol(nf, Decl(intlNumberFormatES2023.ts, 32, 5))
158+
159+
.formatRangeToParts(100, 100)
160+
>formatRangeToParts : Symbol(Intl.NumberFormat.formatRangeToParts, Decl(lib.es2023.intl.d.ts, --, --))
161+
162+
.filter((part) => part.type !== "approximatelySign")
163+
>filter : Symbol(Array.filter, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
164+
>part : Symbol(part, Decl(intlNumberFormatES2023.ts, 40, 11))
165+
>part.type : Symbol(Intl.NumberRangeFormatPart.type, Decl(lib.es2023.intl.d.ts, --, --))
166+
>part : Symbol(part, Decl(intlNumberFormatES2023.ts, 40, 11))
167+
>type : Symbol(Intl.NumberRangeFormatPart.type, Decl(lib.es2023.intl.d.ts, --, --))
168+
169+
.map((part) => part.value)
170+
>map : Symbol(Array.map, Decl(lib.es5.d.ts, --, --))
171+
>part : Symbol(part, Decl(intlNumberFormatES2023.ts, 41, 8))
172+
>part.value : Symbol(Intl.NumberRangeFormatPart.value, Decl(lib.es2023.intl.d.ts, --, --))
173+
>part : Symbol(part, Decl(intlNumberFormatES2023.ts, 41, 8))
174+
>value : Symbol(Intl.NumberRangeFormatPart.value, Decl(lib.es2023.intl.d.ts, --, --))
175+
176+
.join("");
177+
>join : Symbol(Array.join, Decl(lib.es5.d.ts, --, --))
178+

tests/baselines/reference/intlNumberFormatES2023.types

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,3 +376,108 @@ new Intl.NumberFormat('en-GB').format('+Infinity');
376376
>'+Infinity' : "+Infinity"
377377
> : ^^^^^^^^^^^
378378

379+
// Test approximatelySign part type
380+
const nf = new Intl.NumberFormat("en-US", {
381+
>nf : Intl.NumberFormat
382+
> : ^^^^^^^^^^^^^^^^^
383+
>new Intl.NumberFormat("en-US", { style: "currency", currency: "EUR", maximumFractionDigits: 0,}) : Intl.NumberFormat
384+
> : ^^^^^^^^^^^^^^^^^
385+
>Intl.NumberFormat : Intl.NumberFormatConstructor
386+
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
387+
>Intl : typeof Intl
388+
> : ^^^^^^^^^^^
389+
>NumberFormat : Intl.NumberFormatConstructor
390+
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
391+
>"en-US" : "en-US"
392+
> : ^^^^^^^
393+
>{ style: "currency", currency: "EUR", maximumFractionDigits: 0,} : { style: "currency"; currency: string; maximumFractionDigits: number; }
394+
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
395+
396+
style: "currency",
397+
>style : "currency"
398+
> : ^^^^^^^^^^
399+
>"currency" : "currency"
400+
> : ^^^^^^^^^^
401+
402+
currency: "EUR",
403+
>currency : string
404+
> : ^^^^^^
405+
>"EUR" : "EUR"
406+
> : ^^^^^
407+
408+
maximumFractionDigits: 0,
409+
>maximumFractionDigits : number
410+
> : ^^^^^^
411+
>0 : 0
412+
> : ^
413+
414+
});
415+
416+
const filtered = nf
417+
>filtered : string
418+
> : ^^^^^^
419+
>nf .formatRangeToParts(100, 100) .filter((part) => part.type !== "approximatelySign") .map((part) => part.value) .join("") : string
420+
> : ^^^^^^
421+
>nf .formatRangeToParts(100, 100) .filter((part) => part.type !== "approximatelySign") .map((part) => part.value) .join : (separator?: string) => string
422+
> : ^ ^^^ ^^^^^
423+
>nf .formatRangeToParts(100, 100) .filter((part) => part.type !== "approximatelySign") .map((part) => part.value) : string[]
424+
> : ^^^^^^^^
425+
>nf .formatRangeToParts(100, 100) .filter((part) => part.type !== "approximatelySign") .map : <U>(callbackfn: (value: Intl.NumberRangeFormatPart, index: number, array: Intl.NumberRangeFormatPart[]) => U, thisArg?: any) => U[]
426+
> : ^ ^^ ^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^ ^^^^^^^^
427+
>nf .formatRangeToParts(100, 100) .filter((part) => part.type !== "approximatelySign") : Intl.NumberRangeFormatPart[]
428+
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
429+
>nf .formatRangeToParts(100, 100) .filter : { <S extends Intl.NumberRangeFormatPart>(predicate: (value: Intl.NumberRangeFormatPart, index: number, array: Intl.NumberRangeFormatPart[]) => value is S, thisArg?: any): S[]; (predicate: (value: Intl.NumberRangeFormatPart, index: number, array: Intl.NumberRangeFormatPart[]) => unknown, thisArg?: any): Intl.NumberRangeFormatPart[]; }
430+
> : ^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^ ^^^^^^^^^ ^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^ ^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
431+
>nf .formatRangeToParts(100, 100) : Intl.NumberRangeFormatPart[]
432+
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
433+
>nf .formatRangeToParts : (start: number | bigint | Intl.StringNumericLiteral, end: number | bigint | Intl.StringNumericLiteral) => Intl.NumberRangeFormatPart[]
434+
> : ^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
435+
>nf : Intl.NumberFormat
436+
> : ^^^^^^^^^^^^^^^^^
437+
438+
.formatRangeToParts(100, 100)
439+
>formatRangeToParts : (start: number | bigint | Intl.StringNumericLiteral, end: number | bigint | Intl.StringNumericLiteral) => Intl.NumberRangeFormatPart[]
440+
> : ^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
441+
>100 : 100
442+
> : ^^^
443+
>100 : 100
444+
> : ^^^
445+
446+
.filter((part) => part.type !== "approximatelySign")
447+
>filter : { <S extends Intl.NumberRangeFormatPart>(predicate: (value: Intl.NumberRangeFormatPart, index: number, array: Intl.NumberRangeFormatPart[]) => value is S, thisArg?: any): S[]; (predicate: (value: Intl.NumberRangeFormatPart, index: number, array: Intl.NumberRangeFormatPart[]) => unknown, thisArg?: any): Intl.NumberRangeFormatPart[]; }
448+
> : ^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^ ^^^^^^^^^ ^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^ ^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
449+
>(part) => part.type !== "approximatelySign" : (part: Intl.NumberRangeFormatPart) => boolean
450+
> : ^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
451+
>part : Intl.NumberRangeFormatPart
452+
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^
453+
>part.type !== "approximatelySign" : boolean
454+
> : ^^^^^^^
455+
>part.type : keyof Intl.NumberFormatRangePartTypeRegistry
456+
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
457+
>part : Intl.NumberRangeFormatPart
458+
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^
459+
>type : keyof Intl.NumberFormatRangePartTypeRegistry
460+
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
461+
>"approximatelySign" : "approximatelySign"
462+
> : ^^^^^^^^^^^^^^^^^^^
463+
464+
.map((part) => part.value)
465+
>map : <U>(callbackfn: (value: Intl.NumberRangeFormatPart, index: number, array: Intl.NumberRangeFormatPart[]) => U, thisArg?: any) => U[]
466+
> : ^ ^^ ^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^ ^^^^^^^^
467+
>(part) => part.value : (part: Intl.NumberRangeFormatPart) => string
468+
> : ^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
469+
>part : Intl.NumberRangeFormatPart
470+
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^
471+
>part.value : string
472+
> : ^^^^^^
473+
>part : Intl.NumberRangeFormatPart
474+
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^
475+
>value : string
476+
> : ^^^^^^
477+
478+
.join("");
479+
>join : (separator?: string) => string
480+
> : ^ ^^^ ^^^^^
481+
>"" : ""
482+
> : ^^
483+

tests/cases/conformance/es2023/intlNumberFormatES2023.ts

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,23 @@ new Intl.NumberFormat('en-GB').formatRange(10n, 1000n);
2525
new Intl.NumberFormat('en-GB').formatRangeToParts(10, 1000)[0];
2626
new Intl.NumberFormat('en-GB').formatRangeToParts(10n, 1000n)[0];
2727

28-
// Arbitrary-precision string arguments
29-
new Intl.NumberFormat('en-GB').format('-12.3E-4');
30-
new Intl.NumberFormat('en-GB').formatRange('123.4', '567.8');
31-
new Intl.NumberFormat('en-GB').formatRangeToParts('123E-4', '567E8');
32-
new Intl.NumberFormat('en-GB').format('Infinity');
33-
new Intl.NumberFormat('en-GB').format('-Infinity');
34-
new Intl.NumberFormat('en-GB').format('+Infinity');
28+
// Arbitrary-precision string arguments
29+
new Intl.NumberFormat('en-GB').format('-12.3E-4');
30+
new Intl.NumberFormat('en-GB').formatRange('123.4', '567.8');
31+
new Intl.NumberFormat('en-GB').formatRangeToParts('123E-4', '567E8');
32+
new Intl.NumberFormat('en-GB').format('Infinity');
33+
new Intl.NumberFormat('en-GB').format('-Infinity');
34+
new Intl.NumberFormat('en-GB').format('+Infinity');
35+
36+
// Test approximatelySign part type
37+
const nf = new Intl.NumberFormat("en-US", {
38+
style: "currency",
39+
currency: "EUR",
40+
maximumFractionDigits: 0,
41+
});
42+
43+
const filtered = nf
44+
.formatRangeToParts(100, 100)
45+
.filter((part) => part.type !== "approximatelySign")
46+
.map((part) => part.value)
47+
.join("");

0 commit comments

Comments
 (0)