我对Typescript很新。 tsconfig.json中的Target表示什么?
{
"compilerOptions":
{
"sourceMap": true,
"target": "es5",
"module": "commonjs",
"jsx": "react",
"moduleResolution": "classic",
"lib": [ "es2015", "dom", "es2017" ]
}
}
答案 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
我还会根据所处的环境记录我应该定位的目标