javascript - 如何在 tsconfig.json 中设置 'language_in' 选项?

标签 javascript typescript google-closure-compiler tsconfig

我正在尝试使用我的 tsconfig.json 解决使用闭包编译器缩小 TypeScript 应用程序时收到的警告。

我当前的配置:

{
  "compilerOptions": {
    "target": "es5",
    "module": "system",
    "noImplicitAny": false,
    "removeComments": true,
    "preserveConstEnums": true,
    "outFile": "app.js",
    "sourceMap": true
  },
  "files": [ ... ]
}

但是,由于使用关键字 deletefinallyabstract,我收到以下警告:

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/

相关文章:

javascript - 为什么 jquery .click() 在添加 [0] 时对 href 起作用?

javascript - 无法在 JavaScript 中使用我的模型数据

typescript 使用通用类型创建 key

javascript - Typescript:使用 .map 时如何保留长度信息

javascript - Google Closure 编译器,处理 JSC_INEXISTENT_PROPERTY 警告

在递归结束之前,Javascript 不会更改递归函数内部的 CSS

javascript - Angular 8 应用程序,当使用片段与标题重叠时

使用文件中的行来构造命令中的参数的 Windows 批处理文件

javascript - Google Closure 编译器提示 XMLHttpRequest.response 类型

javascript - 是否有等效于 php.net 的 JavaScript?