2

As you can see below, Intl.NumberFormat.formatToParts seems to be missing from Microsoft Edge: formatToParts in Microsoft Edge

However, both MDN and CanIUse tell me I can...

What am I supposed to do? I can't seem to find any website speaking about this issue, nor can I find a polyfill (EDIT: a polyfill is actually available on MDN, but as I said in my last phrase, I am more interested in the reasons why this method is missing whereas both MDN and CanIUse say it is available on Edge).

I am using it like this:

return (_numberFormat as any).formatToParts(val).map(({type, value}) => {
    if (type === 'group')
        return ' ';

    return value;
}).reduce((string, part) => string + part);

(all I am doing is using a proper space character instead of the unicode default one, which is too slim for the liking of my client)

I know I could work around this (performing a basic format, and replacing the unicode space myself afterwards, or implementing a polyfill), but I am far more intrigued by the fact that this method does not seem to exist on Edge whereas everyone on Earth seems convinced that it does.

Any input appreciated :)

Kind regards,

6
  • Hmm.. According to this (developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/…), it is available though.. Commented Apr 5, 2019 at 3:03
  • @wentjun Precisely what I said :) But it is not available, though. And I am surprised that no one seems to be talking about it missing in Edge, anywhere on the web. Commented Apr 6, 2019 at 0:54
  • Most people these days are using a build pipeline that goes through babel outputting ES5 so you can use the latest TypeScript and ES6 syntax but your build is compatible with all ES5 browsers. Commented Apr 9, 2019 at 23:43
  • Thx @AdrianBrand, I am among these people, and I use TypeScript as you may have guessed from the code snippet. Another thing you may have guessed is that formatToParts is missing from TS, well at least from the version I am currently using (hence the as any trick). I'm not quite sure what EcmaScript version I am transpiling my TS files to, I'd have to double-check that. Thanks anyway! Commented Apr 10, 2019 at 20:22
  • Check the "target": "es5" under compiler options in your tsconfig.json file. Commented Apr 11, 2019 at 0:02

1 Answer 1

2

The methods really are missing in Edge:

console.log(typeof Intl.NumberFormat.prototype.formatToParts);
console.log(typeof Intl.DateTimeFormat.prototype.formatToParts);
lists the prototype property types as function in Firefox and undefined in Edge.

Possibly the MDN article was mislead by Microsoft typing the functions in TypeScript (which has nothing to do with them being implemented in Edge) and listing the issue as fixed.


Note that google links for MSDN articles on formatToParts now simply redirect to MDN.


Update regarding listing of Edge support on MDN (https://github.com/mdn/browser-compat-data/pull/3769) (reported in comment by foolip).

Testing and investigation confirms formatFromParts support was added in Edge 18.

However this had not been pushed to my machine through Windows Update as of April 09 2019 (yesterday), and Edge is showing its version information as "Microsoft Edge 42.17134.1.0 EdgeHTML 17.134" under (hamburger dots > settings > about this app). Googling "has windows 1810 been pushed through windows update" reveals a troublesome history which goes as long way to explaining why I am still running Win 1803 and Edge 17.

I suggest the support page on MDN would benefit by replacing "yes" for Edge support with "18" to remove the confusion.

Sign up to request clarification or add additional context in comments.

3 Comments

According to this issue (github.com/Microsoft/TypeScript/issues/25069), it seems to be fixed in TypeScript, which means I must be running an old version of TS (hence the (_numberFormat as any).formatToParts).I decided to use a monospace font so that the thousands separator is wide enough for my client. Thanks for your input!
Intl.NumberFormat.prototype.formatToParts and Intl.DateTimeFormat.prototype.formatToParts do exist in Edge 18. See github.com/mdn/browser-compat-data/pull/… for discussion of this issue in MDN.
@foolip thanks for the link which helped add detail to the answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.