Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/security/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Typescript 如何在tsconfig.json中设置/应用要编译的默认ES?_Typescript - Fatal编程技术网

Typescript 如何在tsconfig.json中设置/应用要编译的默认ES?

Typescript 如何在tsconfig.json中设置/应用要编译的默认ES?,typescript,Typescript,我的TypeScript编译到(可能)ES5,这是最初的默认值 我可以编译成更现代的JavaScript,比如ES2019 tsc main.js -t 'ES2019' 但是,如何将ES2019设置为该项目系统的默认设置 我创建了一个tsconfig.json文件,并将其更改为: $ cat tsconfig.json { "compilerOptions": { // "incremental": true, "target": 'ES2019', "modul

我的TypeScript编译到(可能)ES5,这是最初的默认值

我可以编译成更现代的JavaScript,比如ES2019

tsc main.js -t 'ES2019'
但是,如何将ES2019设置为该项目系统的默认设置

我创建了一个tsconfig.json文件,并将其更改为:

$ cat tsconfig.json
{
  "compilerOptions": {
    // "incremental": true,
    "target": 'ES2019',
    "module": "commonjs",  
    ... 

但是它似乎没有起作用-我使用
tsc main
,我仍然会使用较旧的JavaScript,除非我直接在命令行中使用
tsc main-t'ES2019'指定该选项。
目标需要在
编译器选项
部分中。

配置文件是正确的

问题在于我将源文件作为参数传递

这对我来说似乎不是直觉

如果您使用不带参数的
tsc
,则会使用
tsconfig.json
文件,并尊重并使用
target
ES版本

但是,如果在命令行将文件作为
tsc
的参数传递给编译,则它不会使用
tsconfig.json
文件,并且当我尝试将其与-p一起使用时,我得到了一个错误:

$ tsc main.ts -p tsconfig.json                                                                                                                                                           
error TS5042: Option 'project' cannot be mixed with source files on a command line. 


因此,带有noparam的tsc确实使用
tsconfig
文件和其中的ES版本。

谢谢。我在问题中添加了信息,以显示问题所在。