es6 Map() doesn't compile to es5 when using Typescript

跟風遠走 提交于 2019-12-01 20:36:36

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

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

My first two thoughts are:

You'll need a shim or a polyfill.

I've used es6-map once and it's pretty good.

Unfortunately there is no TypeScript definitions for it, so my suggestion would be using es6-shim directly from a CDN and add this to your tsconfig.json.

{
    "compilerOptions": {
        "target": "es5",
        "lib": ["es6"]
    }
}

You'll be able to use ES6 Map strongly typed, your code will be compiled down to ES5 and old browsers would support it through the shim.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!