IE11 中的 TypeScript Array.from
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/36622505/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
TypeScript Array.from in IE11
提问by chriskelly
Array.fromis an ES6 feature. When I use it in TypeScript and compile to ES5 target it does not change it:
Array.from是 ES6 的一个特性。当我在 TypeScript 中使用它并编译为 ES5 目标时,它不会改变它:
tsc -t es5 prog.ts
i.e. when I look inside prog.js I still see Array.fromin the same place. Using prog.js in IE11 complains as follows:
即当我查看 prog.js 时,我仍然在同一个地方看到Array.from。在 IE11 中使用 prog.js 抱怨如下:
Object doesn't support property or method 'from'
对象不支持“来自”的属性或方法
Why doesn't TypeScript convert Array.fromin to some ES5 alternative?
为什么 TypeScript 不将Array.from转换为某些 ES5 替代方案?
Is there a way to set it up so it does?
有没有办法设置它呢?
采纳答案by Estus Flask
It is a method that can be polyfilled.
这是一种可以polyfill的方法。
Language features that can't be polyfilled are transpiled (if possible on the selected TypeScript target).
不能被 polyfill 的语言功能被转译(如果可能的话,在选定的 TypeScript 目标上)。
回答by Eric Lease
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
.
我建议使用,core-js
因为您将获得更多的 polyfill,而不必零碎地填充 API。如果您只需要/想要的是Array.from
,那么无论如何都可以从 MDN 站点上撕下它,但是您可以有选择地仅导入您需要使用的 polyfill core-js
。
Using npmto install core-js
...
使用npm安装core-js
...
> npm install --save core-js
...then in your .ts
...
......然后在你的.ts
......
import 'core-js' // to get the whole thing
or
或者
import 'core-js/es/array'; // to get just array polyfills for example
回答by Guillaume
The Array.from
doesn't yet exist in TypeScript v1.8 so the compilator leaves as-is this part of code.
在Array.from
还没有在打字稿V1.8存在,因此compilator叶为,是这部分代码。
According to this linkArray.from
isn't supported on IE, so you have to implement a polyfill (see the link, the polyfill is in).
根据此链接Array.from
在 IE 上不受支持,因此您必须实现一个 polyfill(请参阅链接,polyfill 在中)。