question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Intl.NumberFormatOptions type restriction

See original GitHub issue

lib 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

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

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:1
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
ortacommented, Sep 8, 2021

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

0reactions
DPK101commented, Apr 26, 2022

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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found