打字稿 - tsconfig中的目标是什么?

时间:2017-02-23 12:35:46

标签: typescript ecmascript-6 babeljs tsconfig

我对Typescript很新。 tsconfig.json中的Target表示什么?

{
  "compilerOptions": 
  {
    "sourceMap": true,
    "target": "es5",
    "module": "commonjs",
    "jsx": "react",
    "moduleResolution": "classic",
    "lib": [ "es2015", "dom",  "es2017" ]
  }
}

2 个答案:

答案 0 :(得分:52)

  

我对Typescript很新。 tsconfig.json中的Target表示什么?

target表示应从给定的TypeScript 发出哪个JavaScript目标。示例:

target:es5

()=>null将成为function(){return null},因为ES5没有箭头功能。

target:es6

()=>null将成为()=>null,因为ES6具有箭头功能。

答案 1 :(得分:1)

目标更改您要编译的JavaScript版本。

可以在https://www.typescriptlang.org/docs/handbook/compiler-options.html

获得这些选项

本着试图更好地了解目标标志如何更改我的代码的精神,我为每个不同的版本编译了一些测试代码,以更好地理解差异。

https://github.com/aizatto/typescript-playground/tree/master/dist/test-async-main

我还会根据所处的环境记录我应该定位的目标

https://www.aizatto.com/notes/typescript