Intl.NumberFormatOptions type restriction
See original GitHub issuelib Update Request
Configuration Check
My compilation target is ES2015
and my lib is [ "dom", "es5", "es6", "es2017", "scripthost", "es2015.collection", "es2015.promise" ]
.
Missing / Incorrect Definition
the properties of the Intl.NumberFormatOptions
are very generic compared to other Options within the Intl
scope. As for example the localeMatcher
is only a string. For the Intl.DatetimeFormatOption
it is more restrictive. Only ‘best fit’ and ‘lookup’ are allowed. Actually nearly every property of the Intl.NumberFormatOptions
is not restricted as the MDN docs suggest. It would be nice to have type restrictions similar to other types within Intl
.
I think this even applies to other Options-Definitions.
for example: Intl.CollatorOptions
Sample Code
// lib.es5.d.ts
interface DateTimeFormatOptions {
localeMatcher?: "best fit" | "lookup";
weekday?: "long" | "short" | "narrow";
era?: "long" | "short" | "narrow";
year?: "numeric" | "2-digit";
month?: "numeric" | "2-digit" | "long" | "short" | "narrow";
day?: "numeric" | "2-digit";
hour?: "numeric" | "2-digit";
minute?: "numeric" | "2-digit";
second?: "numeric" | "2-digit";
timeZoneName?: "long" | "short";
formatMatcher?: "best fit" | "basic";
hour12?: boolean;
timeZone?: string;
}
// lib.es5.d.ts
interface NumberFormatOptions {
localeMatcher?: string;
style?: string;
currency?: string;
currencyDisplay?: string;
currencySign?: string;
useGrouping?: boolean;
minimumIntegerDigits?: number;
minimumFractionDigits?: number;
maximumFractionDigits?: number;
minimumSignificantDigits?: number;
maximumSignificantDigits?: number;
}
Documentation Link
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:6 (1 by maintainers)
Top Results From Across the Web
NumberFormatOptions is missing several options ... - GitHub
notation is missing from NumberFormatOptions TypeScript/lib/lib.es5.d.ts Line 4236 in ... notation Code const str = new Intl.NumberFormat(und.
Read more >Intl.NumberFormat() constructor - JavaScript - MDN Web Docs
The default maximum digit value is 3 for plain values, 2 for currency, and may have different values for other predefined types. The...
Read more >1.1Abstract Operations For NumberFormat Objects - TC39
The abstract operation SetNumberFormatDigitOptions applies digit options used for number formatting onto the intl object. Assert: Type ( intlObj ) is Object ...
Read more >ECMAScript® 2017 Internationalization API Specification
10.3 Properties of the Intl.Collator Prototype Object ... As an extension to the Record Specification Type, the notation "[[< name >]]" denotes a...
Read more >NumberFormatOptions | typescript - v3.7.7
... "node_modules/typedoc/node_modules/typescript/lib/lib.es5.d" · Intl · NumberFormatOptions. Interface NumberFormatOptions. Hierarchy. NumberFormatOptions ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
In https://github.com/microsoft/TypeScript/pull/45647
NumberFormatOptions
went to string literals for a lot of the parts in . Enough that I think this issue could be closed,Re: the extra type explorations, nice work - I think these are probably a bit long for inclusion into the .d.ts files though
Thanks for creating an issue, I am also looking for NumberformatOptions.compactDisplay and NumberformatOptions.notation
Please keep in sync with MDN docs,
btw, any other ways I can achieve showing number 324234252 as “$324M” in current version of my TypeScript “4.6.3” ? Any help would be appreciated. Thank you