microsoft / microsoft/TypeScript
Intl.NumberFormat does not model required properties when `style` is set to `currency`
Offen
Bug
Domain: lib.d.ts
Help Wanted
Needs Human Review
- Vorherrschende Sprache
- Go
- Sterne
- 111k
- Forks
- 14.4k
- Ø Merge
- 1 T. 19 Std.
- Gemergte PRs (30 T.)
- 117
Beschreibung
⚙ 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
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Bewertung
Dieses Issue wurde noch nicht bewertet.