Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 6 additions & 2 deletions tsc/internal/bundled/libs/lib.es2020.intl.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,10 @@ declare namespace Intl {
unit: never;
}

interface NumberFormatOptionsStyleRequiredOptionsRegistry {
unit: { unit: string };
}

interface NumberFormatOptionsCurrencyDisplayRegistry {
narrowSymbol: never;
}
Expand Down Expand Up @@ -458,8 +462,8 @@ declare namespace Intl {
}

interface NumberFormatConstructor {
new (locales?: LocalesArgument, options?: NumberFormatOptions): NumberFormat;
(locales?: LocalesArgument, options?: NumberFormatOptions): NumberFormat;
new <T extends NumberFormatOptions = NumberFormatOptions>(locales?: LocalesArgument, options?: T & NumberFormatOptionsStyleRequiredOptions<T["style"]>): NumberFormat;
<T extends NumberFormatOptions = NumberFormatOptions>(locales?: LocalesArgument, options?: T & NumberFormatOptionsStyleRequiredOptions<T["style"]>): NumberFormat;
supportedLocalesOf(locales: LocalesArgument, options?: NumberFormatOptions): string[];
}

Expand Down
14 changes: 12 additions & 2 deletions tsc/internal/bundled/libs/lib.es5.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4455,6 +4455,16 @@ declare namespace Intl {

type NumberFormatOptionsStyle = keyof NumberFormatOptionsStyleRegistry;

interface NumberFormatOptionsStyleRequiredOptionsRegistry {
decimal: {};
percent: {};
currency: { currency: string };
}

type NumberFormatOptionsStyleRequiredOptions<Style> = Style extends keyof NumberFormatOptionsStyleRequiredOptionsRegistry
? NumberFormatOptionsStyleRequiredOptionsRegistry[Style]
: {};

interface NumberFormatOptionsCurrencyDisplayRegistry {
code: never;
symbol: never;
Expand Down Expand Up @@ -4501,8 +4511,8 @@ declare namespace Intl {
}

interface NumberFormatConstructor {
new (locales?: string | string[], options?: NumberFormatOptions): NumberFormat;
(locales?: string | string[], options?: NumberFormatOptions): NumberFormat;
new <T extends NumberFormatOptions = NumberFormatOptions>(locales?: string | string[], options?: T & NumberFormatOptionsStyleRequiredOptions<T["style"]>): NumberFormat;
<T extends NumberFormatOptions = NumberFormatOptions>(locales?: string | string[], options?: T & NumberFormatOptionsStyleRequiredOptions<T["style"]>): NumberFormat;
supportedLocalesOf(locales: string | string[], options?: NumberFormatOptions): string[];
readonly prototype: NumberFormat;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
intlNumberFormatRequiredStyleOptions.ts(3,32): error TS2769: No overload matches this call.
The last overload gave the following error.
Argument of type '{ style: "currency"; }' is not assignable to parameter of type '{ style: "currency"; } & { currency: string; }'.
Property 'currency' is missing in type '{ style: "currency"; }' but required in type '{ currency: string; }'.
intlNumberFormatRequiredStyleOptions.ts(4,32): error TS2769: No overload matches this call.
The last overload gave the following error.
Argument of type '{ style: "currency"; currency: undefined; }' is not assignable to parameter of type 'undefined'.
intlNumberFormatRequiredStyleOptions.ts(8,32): error TS2769: No overload matches this call.
The last overload gave the following error.
Argument of type '{ style: "unit"; }' is not assignable to parameter of type '{ style: "unit"; } & { unit: string; }'.
Property 'unit' is missing in type '{ style: "unit"; }' but required in type '{ unit: string; }'.
intlNumberFormatRequiredStyleOptions.ts(9,32): error TS2769: No overload matches this call.
The last overload gave the following error.
Argument of type '{ style: "unit"; unit: undefined; }' is not assignable to parameter of type 'undefined'.


==== intlNumberFormatRequiredStyleOptions.ts (4 errors) ====
// Currency style requires a currency to be specified.
new Intl.NumberFormat('en-NZ', { style: 'currency', currency: 'NZD' });
new Intl.NumberFormat('en-NZ', { style: 'currency' });
~~~~~~~~~~~~~~~~~~~~~
!!! error TS2769: No overload matches this call.
!!! error TS2769: The last overload gave the following error.
!!! error TS2769: Argument of type '{ style: "currency"; }' is not assignable to parameter of type '{ style: "currency"; } & { currency: string; }'.
!!! error TS2769: Property 'currency' is missing in type '{ style: "currency"; }' but required in type '{ currency: string; }'.
!!! related TS2728 lib.es5.d.ts:--:--: 'currency' is declared here.
!!! related TS2771 lib.es5.d.ts:--:--: The last overload is declared here.
new Intl.NumberFormat('en-NZ', { style: 'currency', currency: undefined });
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2769: No overload matches this call.
!!! error TS2769: The last overload gave the following error.
!!! error TS2769: Argument of type '{ style: "currency"; currency: undefined; }' is not assignable to parameter of type 'undefined'.
!!! related TS2771 lib.es5.d.ts:--:--: The last overload is declared here.

// Unit style requires a unit to be specified.
new Intl.NumberFormat('en-NZ', { style: 'unit', unit: 'kilogram' });
new Intl.NumberFormat('en-NZ', { style: 'unit' });
~~~~~~~~~~~~~~~~~
!!! error TS2769: No overload matches this call.
!!! error TS2769: The last overload gave the following error.
!!! error TS2769: Argument of type '{ style: "unit"; }' is not assignable to parameter of type '{ style: "unit"; } & { unit: string; }'.
!!! error TS2769: Property 'unit' is missing in type '{ style: "unit"; }' but required in type '{ unit: string; }'.
!!! related TS2728 lib.es2020.intl.d.ts:--:--: 'unit' is declared here.
!!! related TS2771 lib.es5.d.ts:--:--: The last overload is declared here.
new Intl.NumberFormat('en-NZ', { style: 'unit', unit: undefined });
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2769: No overload matches this call.
!!! error TS2769: The last overload gave the following error.
!!! error TS2769: Argument of type '{ style: "unit"; unit: undefined; }' is not assignable to parameter of type 'undefined'.
!!! related TS2771 lib.es5.d.ts:--:--: The last overload is declared here.

// Other styles do not require currency/unit.
new Intl.NumberFormat('en-NZ', { style: 'decimal' });
new Intl.NumberFormat('en-NZ', { style: 'percent' });
new Intl.NumberFormat('en-NZ');
new Intl.NumberFormat('en-NZ', {});

// Widened option bags are not checked for the required relationship.
declare const currencyOptions: Intl.NumberFormatOptions;
new Intl.NumberFormat('en-NZ', currencyOptions);

Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
//// [tests/cases/conformance/es2020/intlNumberFormatRequiredStyleOptions.ts] ////

//// [intlNumberFormatRequiredStyleOptions.ts]
// Currency style requires a currency to be specified.
new Intl.NumberFormat('en-NZ', { style: 'currency', currency: 'NZD' });
new Intl.NumberFormat('en-NZ', { style: 'currency' });
new Intl.NumberFormat('en-NZ', { style: 'currency', currency: undefined });

// Unit style requires a unit to be specified.
new Intl.NumberFormat('en-NZ', { style: 'unit', unit: 'kilogram' });
new Intl.NumberFormat('en-NZ', { style: 'unit' });
new Intl.NumberFormat('en-NZ', { style: 'unit', unit: undefined });

// Other styles do not require currency/unit.
new Intl.NumberFormat('en-NZ', { style: 'decimal' });
new Intl.NumberFormat('en-NZ', { style: 'percent' });
new Intl.NumberFormat('en-NZ');
new Intl.NumberFormat('en-NZ', {});

// Widened option bags are not checked for the required relationship.
declare const currencyOptions: Intl.NumberFormatOptions;
new Intl.NumberFormat('en-NZ', currencyOptions);


//// [intlNumberFormatRequiredStyleOptions.js]
"use strict";
// Currency style requires a currency to be specified.
new Intl.NumberFormat('en-NZ', { style: 'currency', currency: 'NZD' });
new Intl.NumberFormat('en-NZ', { style: 'currency' });
new Intl.NumberFormat('en-NZ', { style: 'currency', currency: undefined });
// Unit style requires a unit to be specified.
new Intl.NumberFormat('en-NZ', { style: 'unit', unit: 'kilogram' });
new Intl.NumberFormat('en-NZ', { style: 'unit' });
new Intl.NumberFormat('en-NZ', { style: 'unit', unit: undefined });
// Other styles do not require currency/unit.
new Intl.NumberFormat('en-NZ', { style: 'decimal' });
new Intl.NumberFormat('en-NZ', { style: 'percent' });
new Intl.NumberFormat('en-NZ');
new Intl.NumberFormat('en-NZ', {});
new Intl.NumberFormat('en-NZ', currencyOptions);
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
//// [tests/cases/conformance/es2020/intlNumberFormatRequiredStyleOptions.ts] ////

=== intlNumberFormatRequiredStyleOptions.ts ===
// Currency style requires a currency to be specified.
new Intl.NumberFormat('en-NZ', { style: 'currency', currency: 'NZD' });
>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, --, --))
>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 2 more)
>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, --, --))
>style : Symbol(style, Decl(intlNumberFormatRequiredStyleOptions.ts, 1, 32))
>currency : Symbol(currency, Decl(intlNumberFormatRequiredStyleOptions.ts, 1, 51))

new Intl.NumberFormat('en-NZ', { style: 'currency' });
>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, --, --))
>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 2 more)
>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, --, --))
>style : Symbol(style, Decl(intlNumberFormatRequiredStyleOptions.ts, 2, 32))

new Intl.NumberFormat('en-NZ', { style: 'currency', currency: undefined });
>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, --, --))
>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 2 more)
>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, --, --))
>style : Symbol(style, Decl(intlNumberFormatRequiredStyleOptions.ts, 3, 32))
>currency : Symbol(currency, Decl(intlNumberFormatRequiredStyleOptions.ts, 3, 51))
>undefined : Symbol(undefined)

// Unit style requires a unit to be specified.
new Intl.NumberFormat('en-NZ', { style: 'unit', unit: 'kilogram' });
>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, --, --))
>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 2 more)
>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, --, --))
>style : Symbol(style, Decl(intlNumberFormatRequiredStyleOptions.ts, 6, 32))
>unit : Symbol(unit, Decl(intlNumberFormatRequiredStyleOptions.ts, 6, 47))

new Intl.NumberFormat('en-NZ', { style: 'unit' });
>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, --, --))
>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 2 more)
>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, --, --))
>style : Symbol(style, Decl(intlNumberFormatRequiredStyleOptions.ts, 7, 32))

new Intl.NumberFormat('en-NZ', { style: 'unit', unit: undefined });
>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, --, --))
>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 2 more)
>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, --, --))
>style : Symbol(style, Decl(intlNumberFormatRequiredStyleOptions.ts, 8, 32))
>unit : Symbol(unit, Decl(intlNumberFormatRequiredStyleOptions.ts, 8, 47))
>undefined : Symbol(undefined)

// Other styles do not require currency/unit.
new Intl.NumberFormat('en-NZ', { style: 'decimal' });
>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, --, --))
>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 2 more)
>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, --, --))
>style : Symbol(style, Decl(intlNumberFormatRequiredStyleOptions.ts, 11, 32))

new Intl.NumberFormat('en-NZ', { style: 'percent' });
>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, --, --))
>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 2 more)
>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, --, --))
>style : Symbol(style, Decl(intlNumberFormatRequiredStyleOptions.ts, 12, 32))

new Intl.NumberFormat('en-NZ');
>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, --, --))
>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 2 more)
>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, --, --))

new Intl.NumberFormat('en-NZ', {});
>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, --, --))
>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 2 more)
>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, --, --))

// Widened option bags are not checked for the required relationship.
declare const currencyOptions: Intl.NumberFormatOptions;
>currencyOptions : Symbol(currencyOptions, Decl(intlNumberFormatRequiredStyleOptions.ts, 17, 13))
>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 2 more)
>NumberFormatOptions : Symbol(Intl.NumberFormatOptions, Decl(lib.es5.d.ts, --, --), Decl(lib.es2020.intl.d.ts, --, --))

new Intl.NumberFormat('en-NZ', currencyOptions);
>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, --, --))
>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 2 more)
>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, --, --))
>currencyOptions : Symbol(currencyOptions, Decl(intlNumberFormatRequiredStyleOptions.ts, 17, 13))

Loading