我正在尝试使用我的 tsconfig.json
解决使用闭包编译器缩小 TypeScript 应用程序时收到的警告。
我当前的配置:
{
"compilerOptions": {
"target": "es5",
"module": "system",
"noImplicitAny": false,
"removeComments": true,
"preserveConstEnums": true,
"outFile": "app.js",
"sourceMap": true
},
"files": [ ... ]
}
但是,由于使用关键字 delete
、finally
和 abstract
,我收到以下警告:
WARNING - Keywords and reserved words are not allowed as unquoted property names in older versions of JavaScript. If you are targeting newer versions of JavaScript, set the appropriate language_in option.
我确实看到了答案,How can I set the language_in option for the Closure compiler?这建议使用 --compiler_flags="--language_in=ECMASCRIPT5"
来解决,但这就是我认为 "target": "es5"
在我的 中所做的tsconfig.json
?
因此,尽管设置了 target
,但我看不到其他配置选项可以达到 language_in
具有 read the tsconfig.json
spec 的效果。 ,不知道如何解决。
显然,我可以引用属性名称,或忽略警告,但我希望解决这些警告,因为我不针对较旧的浏览器。
最佳答案
tsconfig.json
由 TypeScript 编译器使用,将 Closure 编译器选项插入其中是行不通的,并且 Closure 编译器不知道如何处理 tsconfig。无论如何,json 。 Closure 编译器的输入应该是 JavaScript(ES3、ES5 或 ES6),而不是 TypeScript,因此您需要设置构建过程以将 TypeScript 源编译为 JavaScript,然后将 JavaScript 提供给 Closure 编译器。在问题中,您将选项链接到 Closure 编译器,并在调用它时在命令行上传递。
关于javascript - 如何在 tsconfig.json 中设置 'language_in' 选项?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35150736/