在 tsconfig.json
中,target
表示什么?
{
"compilerOptions":
{
"sourceMap": true,
"target": "es5",
"module": "commonjs",
"jsx": "react",
"moduleResolution": "classic",
"lib": [ "es2015", "dom", "es2017" ]
}
}
在 tsconfig.json
中,target
表示什么?
{
"compilerOptions":
{
"sourceMap": true,
"target": "es5",
"module": "commonjs",
"jsx": "react",
"moduleResolution": "classic",
"lib": [ "es2015", "dom", "es2017" ]
}
}
target
表示从给定的TypeScript发出哪个JavaScript目标。例如:
target:es5
()=>null
将变为function(){return null}
,因为ES5没有箭头函数。
target:es6
()=>null
将变为()=>null
,因为ES6具有箭头函数。
我还制作了一个快速的有关此主题的视频。
Target 用于指定编译后的 JavaScript 版本。
相关选项请查看 https://www.typescriptlang.org/docs/handbook/compiler-options.html
为了更好地理解 Target 标志如何改变我的代码,我编译了一些测试代码到不同的版本,以便更好地理解它们之间的差异。
https://github.com/aizatto/typescript-playground/tree/master/dist/test-async-main
我还在记录根据不同环境需要使用哪个 Target 版本。
es2017
,那么这就是具有新库引用共享内存和字符串的最新版本。更改您的目标意味着更改代码编译时使用的库。如果您想保持目标低版本同时支持高版本引用的库,则可以将所需的库添加到tsconfig.json
中的"lib"
中。