【问题标题】:Effect of TARGET property inside tsconfig.jsontsconfig.json 中 TARGET 属性的效果
【发布时间】:2020-11-02 08:21:14
【问题描述】:

下面是我项目的tsconfig.json

{
    "compilerOptions": {
        "module": "commonjs",
        "esModuleInterop": true,
        "emitDecoratorMetadata": true,
        "experimentalDecorators": true,
        "allowSyntheticDefaultImports": true,
        "strict": true,
        "target": "es6",
        "noImplicitAny": true,
        "moduleResolution": "node",
        "sourceMap": true,
        "outDir": "dist",
        "baseUrl": ".",
        "typeRoots": [
            "src/types",
            "node_modules/@types",
        ]
    },
    "include": [
        "src/**/*"
    ]
} 

我的 Typescript 版本是 "typescript": "^3.9.5" 和 Node 版本我们 ts-node": "^8.10.2".

我只是想确认我是否将tsconfig.json 文件中的target 更改为"target": "es6" to "target": "es2020"`。它将如何影响我当前的项目或者我很好。

【问题讨论】:

  • 我怀疑 node 8.10 确实支持 ES2020。

标签: javascript node.js typescript ecmascript-6 ecmascript-2020


【解决方案1】:

TypeScript 是 ES6 的超集,因此您实际上是在使用 ES6 版本的 JavaScript 编写 TS 代码。但是,编译后,生成的 JS 代码可以在 ES5 或更早版本中。您需要定义编译器应该转译成哪个版本的 JS。这可以使用 target 选项设置

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-01-14
    • 2020-11-01
    • 1970-01-01
    • 2020-12-15
    • 1970-01-01
    • 2017-12-08
    • 2020-09-08
    • 2016-03-22
    相关资源
    最近更新 更多