Skip to content

Commit 5de28db

Browse files
Add approximatelySign to NumberFormatPartTypeRegistry for ES2023
Co-authored-by: RyanCavanaugh <6685088+RyanCavanaugh@users.noreply.github.com>
1 parent 64a51e8 commit 5de28db

File tree

5 files changed

+205
-16
lines changed

5 files changed

+205
-16
lines changed

src/lib/es2023.intl.d.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
1-
declare namespace Intl {
2-
interface NumberFormatOptionsUseGroupingRegistry {
3-
min2: never;
4-
auto: never;
5-
always: never;
6-
}
7-
8-
interface NumberFormatOptionsSignDisplayRegistry {
9-
negative: never;
1+
declare namespace Intl {
2+
interface NumberFormatOptionsUseGroupingRegistry {
3+
min2: never;
4+
auto: never;
5+
always: never;
6+
}
7+
8+
interface NumberFormatOptionsSignDisplayRegistry {
9+
negative: never;
10+
}
11+
12+
interface NumberFormatPartTypeRegistry {
13+
approximatelySign: never;
1014
}
1115

1216
interface NumberFormatOptions {

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+
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+
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: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,3 +130,48 @@ 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+
nf
152+
>nf .formatRangeToParts(100, 100) .filter((part) => part.type !== "approximatelySign") .map((part) => part.value) .join : Symbol(Array.join, Decl(lib.es5.d.ts, --, --))
153+
>nf .formatRangeToParts(100, 100) .filter((part) => part.type !== "approximatelySign") .map : Symbol(Array.map, Decl(lib.es5.d.ts, --, --))
154+
>nf .formatRangeToParts(100, 100) .filter : Symbol(Array.filter, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
155+
>nf .formatRangeToParts : Symbol(Intl.NumberFormat.formatRangeToParts, Decl(lib.es2023.intl.d.ts, --, --))
156+
>nf : Symbol(nf, Decl(intlNumberFormatES2023.ts, 32, 5))
157+
158+
.formatRangeToParts(100, 100)
159+
>formatRangeToParts : Symbol(Intl.NumberFormat.formatRangeToParts, Decl(lib.es2023.intl.d.ts, --, --))
160+
161+
.filter((part) => part.type !== "approximatelySign")
162+
>filter : Symbol(Array.filter, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
163+
>part : Symbol(part, Decl(intlNumberFormatES2023.ts, 40, 11))
164+
>part.type : Symbol(Intl.NumberFormatPart.type, Decl(lib.es2018.intl.d.ts, --, --))
165+
>part : Symbol(part, Decl(intlNumberFormatES2023.ts, 40, 11))
166+
>type : Symbol(Intl.NumberFormatPart.type, Decl(lib.es2018.intl.d.ts, --, --))
167+
168+
.map((part) => part.value)
169+
>map : Symbol(Array.map, Decl(lib.es5.d.ts, --, --))
170+
>part : Symbol(part, Decl(intlNumberFormatES2023.ts, 41, 8))
171+
>part.value : Symbol(Intl.NumberFormatPart.value, Decl(lib.es2018.intl.d.ts, --, --))
172+
>part : Symbol(part, Decl(intlNumberFormatES2023.ts, 41, 8))
173+
>value : Symbol(Intl.NumberFormatPart.value, Decl(lib.es2018.intl.d.ts, --, --))
174+
175+
.join("");
176+
>join : Symbol(Array.join, Decl(lib.es5.d.ts, --, --))
177+

tests/baselines/reference/intlNumberFormatES2023.types

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,3 +376,106 @@ 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+
nf
417+
>nf .formatRangeToParts(100, 100) .filter((part) => part.type !== "approximatelySign") .map((part) => part.value) .join("") : string
418+
> : ^^^^^^
419+
>nf .formatRangeToParts(100, 100) .filter((part) => part.type !== "approximatelySign") .map((part) => part.value) .join : (separator?: string) => string
420+
> : ^ ^^^ ^^^^^
421+
>nf .formatRangeToParts(100, 100) .filter((part) => part.type !== "approximatelySign") .map((part) => part.value) : string[]
422+
> : ^^^^^^^^
423+
>nf .formatRangeToParts(100, 100) .filter((part) => part.type !== "approximatelySign") .map : <U>(callbackfn: (value: Intl.NumberRangeFormatPart, index: number, array: Intl.NumberRangeFormatPart[]) => U, thisArg?: any) => U[]
424+
> : ^ ^^ ^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^ ^^^^^^^^
425+
>nf .formatRangeToParts(100, 100) .filter((part) => part.type !== "approximatelySign") : Intl.NumberRangeFormatPart[]
426+
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
427+
>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[]; }
428+
> : ^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^ ^^^^^^^^^ ^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^ ^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
429+
>nf .formatRangeToParts(100, 100) : Intl.NumberRangeFormatPart[]
430+
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
431+
>nf .formatRangeToParts : (start: number | bigint | Intl.StringNumericLiteral, end: number | bigint | Intl.StringNumericLiteral) => Intl.NumberRangeFormatPart[]
432+
> : ^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
433+
>nf : Intl.NumberFormat
434+
> : ^^^^^^^^^^^^^^^^^
435+
436+
.formatRangeToParts(100, 100)
437+
>formatRangeToParts : (start: number | bigint | Intl.StringNumericLiteral, end: number | bigint | Intl.StringNumericLiteral) => Intl.NumberRangeFormatPart[]
438+
> : ^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
439+
>100 : 100
440+
> : ^^^
441+
>100 : 100
442+
> : ^^^
443+
444+
.filter((part) => part.type !== "approximatelySign")
445+
>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[]; }
446+
> : ^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^ ^^^^^^^^^ ^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^ ^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
447+
>(part) => part.type !== "approximatelySign" : (part: Intl.NumberRangeFormatPart) => boolean
448+
> : ^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
449+
>part : Intl.NumberRangeFormatPart
450+
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^
451+
>part.type !== "approximatelySign" : boolean
452+
> : ^^^^^^^
453+
>part.type : keyof Intl.NumberFormatPartTypeRegistry
454+
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
455+
>part : Intl.NumberRangeFormatPart
456+
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^
457+
>type : keyof Intl.NumberFormatPartTypeRegistry
458+
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
459+
>"approximatelySign" : "approximatelySign"
460+
> : ^^^^^^^^^^^^^^^^^^^
461+
462+
.map((part) => part.value)
463+
>map : <U>(callbackfn: (value: Intl.NumberRangeFormatPart, index: number, array: Intl.NumberRangeFormatPart[]) => U, thisArg?: any) => U[]
464+
> : ^ ^^ ^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^ ^^^^^^^^
465+
>(part) => part.value : (part: Intl.NumberRangeFormatPart) => string
466+
> : ^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
467+
>part : Intl.NumberRangeFormatPart
468+
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^
469+
>part.value : string
470+
> : ^^^^^^
471+
>part : Intl.NumberRangeFormatPart
472+
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^
473+
>value : string
474+
> : ^^^^^^
475+
476+
.join("");
477+
>join : (separator?: string) => string
478+
> : ^ ^^^ ^^^^^
479+
>"" : ""
480+
> : ^^
481+

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+
nf
44+
.formatRangeToParts(100, 100)
45+
.filter((part) => part.type !== "approximatelySign")
46+
.map((part) => part.value)
47+
.join("");

0 commit comments

Comments
 (0)