使用Typescript时,es6 Map()无法编译为es5 [英] es6 Map() doesn't compile to es5 when using Typescript

查看:303
本文介绍了使用Typescript时,es6 Map()无法编译为es5的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚开始在项目中使用Typescript.

I've just started using Typescript in a project for the first time.

我真的很想使用Map()来组织一小列键值对.

I really want to use Map() to organize a small array of key value pairs.

不幸的是,当打字稿被编译(使用gulp和gulp-typescript)转换为普通版本时,ES5 JavaScript,Map()仍然存在.我需要这段代码才能在ie9中工作.

Unfortunately when the typescript is compiled (using gulp and gulp-typescript) to vanilla, ES5 JavaScript, Map() still exists. I need this code to work in ie9.

此阶段的任何建议将不胜感激.

Any advice at this stage would be greatly appreciated.

推荐答案

Map是ES6的一部分,与TypeScript无关.

Map is a part of ES6 and have nothing to do with TypeScript.

如果要在ES5环境中使用Map,则应包括适当的polyfill.

If you want tot use Map in ES5 environment you should include an appropriate polyfill.

我的前两个想法是:

  • es6-map module
  • core-js/es6/map from core-js generic ES6 polyfill library

这篇关于使用Typescript时,es6 Map()无法编译为es5的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆