Javascript Typescript- tsconfig 中的目标是什么?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/42415942/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 01:08:05  来源:igfitidea点击:

Typescript- What is target in tsconfig?

javascripttypescripttsconfigtranspiler

提问by Ankit Raonka

I am quite new to Typescript. What does Target in tsconfig.json signify?

我对打字稿很陌生。tsconfig.json 中的 Target 是什么意思?

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

回答by basarat

I am quite new to Typescript. What does Target in tsconfig.json signify?

我对打字稿很陌生。tsconfig.json 中的 Target 是什么意思?

targetsignifies which target of JavaScript should be emitted from the given TypeScript. Examples:

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

target:es5

target:es5

()=>nullwill become function(){return null}as ES5 doesn't have arrow functions.

()=>null会变成function(){return null}ES5 没有箭头函数。

target:es6

target:es6

()=>nullwill become ()=>nullas ES6 has arrow functions.

()=>null将成为()=>nullES6 具有箭头功能。

回答by aizatto

Target changes the JavaScript version you are compiling to.

Target 会更改您正在编译的 JavaScript 版本。

The options are available at https://www.typescriptlang.org/docs/handbook/compiler-options.html

这些选项可在https://www.typescriptlang.org/docs/handbook/compiler-options.html 获得

In the spirit of trying to better understand how the target flag changes my code I compiled some test code to each of the different versions to have a better understanding of the differences.

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

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

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

I'm also keeping notes of what I should be targeting depending on what environment I am looking at

我还会根据我正在查看的环境记录我应该瞄准的目标

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

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