Chrome Dev Tools Issue With ES6 String Literals/Typescript

后端 未结 3 2013
离开以前
离开以前 2021-02-01 00:37

I am working on a project using Typescript and some of the ES6 features exposed by Typescript like ES6 String Literals e.g. `Something ${variable} Something else`.<

3条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-02-01 01:08

    If you are using Typescript, you can work around this issue by compiling your code to ES2015 and using source maps. This way, the backtick interpolated strings would be converted to the good ol' "string " + variable + " string", but you would still be able to debug while looking at the original typescript code with backticks.

    This would require adding the following to your tsconfig.json:

    {
        "compilerOptions": {
            "target": "ES2015",
            "sourceMap": true, 
            ...
        }
        ...
    }
    

    And if you serve locally the generated source map files (.js.map) alongside the generated .js files, you should be able to open the typescript files in chrome dev tools under "Sources" with Ctrl-p.

提交回复
热议问题