microsoft / microsoft/TypeScript

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

Aperta
#57,514 2 commenti 4 reazioni 2 assegnatari Vedi su GitHub

@RyanCavanaugh ci sta già lavorando.

Dal 19/9/2026.

  • #64335 di @copilot-swe-agent — aperta
Bug Domain: lib.d.ts Help Wanted Needs Human Review
Lingua principale
Go
Stelle
111k
Fork
14.3k
Merge medio
1g 19h
PR unite (30g)
117

Descrizione

⚙ Compilation target

ESNext

⚙ Library

ESNext

Missing / Incorrect Definition

According to the MDN docs, when style is set to currency, then the currency property must be provided.

This could be achieved through a discriminating union on the style property e.g.

interface NumberFormatParamsStyleDecimal {
    style: "decimal"
}

interface NumberFormatParamsStyleCurrency {
    style: "currency"
    currency: string
}

type NumberFormatParams = NumberFormatParamsStyleDecimal | NumberFormatParamsStyleCurrency;

const numberFormat = (params: NumberFormatParams) => {};

numberFormat({
    style: "decimal",
})

numberFormat({
    style: "currency",
    currency: "USD"
})
Sample Code
This fails at runtime, but does not fail compilation:

new Intl.NumberFormat("en", {
    style: "currency",
    currency: undefined
});
VM159:1 Uncaught TypeError: Currency code is required with currency style.
    at new NumberFormat (<anonymous>)
    at <anonymous>:1:1
Documentation Link

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat#style

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.