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

问题描述 投票:41回答:2

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

{
  "compilerOptions": 
  {
    "sourceMap": true,
    "target": "es5",
    "module": "commonjs",
    "jsx": "react",
    "moduleResolution": "classic",
    "lib": [ "es2015", "dom",  "es2017" ]
  }
}
typescript ecmascript-6 babeljs tsconfig
2个回答
64
投票

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

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

target:es5

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

target:es6

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


1
投票

Target会更改您要编译的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

© www.soinside.com 2019 - 2024. All rights reserved.