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

后端 未结 2 615
一整个雨季
一整个雨季 2021-01-18 16:37

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

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

Unfortunately

2条回答
  •  抹茶落季
    2021-01-18 17:15

    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.

提交回复
热议问题