TypeScript Array.from in IE11

16,578

Solution 1

It is a method that can be polyfilled.

Language features that can't be polyfilled are transpiled (if possible on the selected TypeScript target).

Solution 2

I would recommend using core-js as you'll get many more polyfills and won't have to polyfill APIs piecemeal. If all you need/want is Array.from, then by all means rip it from the MDN site, but you can selectively import just the polyfills you need using core-js.

Using npm to install core-js...

> npm install --save core-js

...then in your .ts...

import 'core-js' // to get the whole thing

or

import 'core-js/es/array'; // to get just array polyfills for example

Solution 3

The Array.from doesn't yet exist in TypeScript v1.8 so the compilator leaves as-is this part of code.

According to this link Array.from isn't supported on IE, so you have to implement a polyfill (see the link, the polyfill is in).

Share:
16,578
chriskelly
Author by

chriskelly

Software developer with an interest in web programming and data visualization.

Updated on June 17, 2022

Comments

  • chriskelly
    chriskelly almost 2 years

    Array.from is an ES6 feature. When I use it in TypeScript and compile to ES5 target it does not change it:

    tsc -t es5 prog.ts
    

    i.e. when I look inside prog.js I still see Array.from in the same place. Using prog.js in IE11 complains as follows:

    Object doesn't support property or method 'from'

    Why doesn't TypeScript convert Array.from in to some ES5 alternative?

    Is there a way to set it up so it does?

  • Thomas Praxl
    Thomas Praxl almost 7 years
    Thanks. Your tip helped me a lot. BTW: actually, it's import 'core-js/es6/array';
  • Cobertos
    Cobertos over 4 years
    it's import 'core-js/es/array'; now