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

查看:42
本文介绍了使用 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.

不幸的是,当 typescript 被编译(使用 gulp 和 gulp-typescript)到 vanilla 时,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天全站免登陆