Skip to content

Model required currency/unit options for Intl.NumberFormat currency/unit styles - #64335

Draft
Ryan Cavanaugh (RyanCavanaugh) with Copilot wants to merge 2 commits into
mainfrom
copilot/fix-intl-numberformat-currency-issue
Draft

Ryan Cavanaugh (RyanCavanaugh) with Copilot wants to merge 2 commits into
mainfrom
copilot/fix-intl-numberformat-currency-issue

Conversation

Copilot AI commented Sep 19, 2026

Copy link
Copy Markdown
Contributor

Intl.NumberFormatOptions allowed style: "currency" without a currency string (or with currency: undefined), which compiles cleanly under --strict but throws TypeError: Currency code is required with currency style. at runtime. Same gap exists for style: "unit" / unit.

// Previously compiled fine, threw at runtime:
new Intl.NumberFormat("en", { style: "currency", currency: undefined });

Changes

  • Added a new extensible registry, NumberFormatOptionsStyleRequiredOptionsRegistry (lib.es5.d.ts), mapping each style name to the extra properties required for that style (currency: { currency: string } in lib.es5.d.ts, unit: { unit: string } added in lib.es2020.intl.d.ts).
  • NumberFormatConstructor's call/construct signatures are now generic over the options object, intersecting it with NumberFormatOptionsStyleRequiredOptions<T["style"]> computed from the registry — mirrors the discriminated-overload pattern already used elsewhere in lib.d.ts (e.g. addEventListener), avoiding a breaking rewrite of NumberFormatOptions into a full union that would conflict with its declaration-merging registry pattern across lib versions.
  • supportedLocalesOf is left untouched, since it doesn't perform this runtime validation.
  • Non-literal option bags (e.g. a variable typed as NumberFormatOptions) are unaffected — the check only applies when style is inferred as a literal from an object literal argument.
new Intl.NumberFormat("en", { style: "currency", currency: "USD" }); // ok
new Intl.NumberFormat("en", { style: "currency" }); // error: currency required
new Intl.NumberFormat("en", { style: "unit", unit: "kilogram" }); // ok
new Intl.NumberFormat("en", { style: "unit" }); // error: unit required

Tests

  • Added intlNumberFormatRequiredStyleOptions.ts covering both new error cases and previously-valid usages that must remain unaffected.

…nit styles

Co-authored-by: RyanCavanaugh <6685088+RyanCavanaugh@users.noreply.github.com>
@typescript-automation typescript-automation Bot added For Uncommitted Bug PR for untriaged, rejected, closed or missing bug and removed For Milestone Bug PRs that fix a bug with a specific milestone labels Sep 19, 2026
Copilot AI changed the title [WIP] Fix Intl.NumberFormat missing properties for currency style Model required currency/unit options for Intl.NumberFormat currency/unit styles Sep 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

For Uncommitted Bug PR for untriaged, rejected, closed or missing bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Intl.NumberFormat does not model required properties when style is set to currency

2 participants