typescript - Visual Studio Code 未编译所有 *.ts 文件

标签 typescript visual-studio-code

我正在尝试使用 Typescript 设置 VSC,但我无法让 VSC 使用 Ctrl + Shift + B 编译所有 *.ts 文件。
我已经阅读了许多关于如何使用 VSC 设置 Typescript 的教程,但我没有成功。

我的 tsconfig.json 文件(位于根目录)如下所示:

{
    "compilerOptions": {
        "target": "ES5",
        "module": "amd",
        "sourceMap": true,
        "outFile": "all.js"
    }
}

和 tasks.json 文件(位于 root/.vscode 中):

{
    "version": "0.1.0",
    "command": "tsc", // it should be tsc.cmd instead of tsc
    "isShellCommand": true,
    "showOutput": "silent",
    "args": [ ],
    "problemMatcher": "$tsc"
}  

当我输入 "args": ["${file}"] 时,它会编译当前文件,不是在 all.js 中,而是在 typescript-file-name.js 中,就像它忽略 tsconfig 文件一样。

VSC 可以使用自己的任务运行器编译所有 *.ts 文件吗?如何设置?

更新
正如我所说,我已经尝试过很多教程,说要将 args 留空,放置“-p”,“。”在其中,使用 npm install -g typescript,检查路径变量……这些都不起作用。

缺少的是 tasks.json 中的 tsc.cmd 命令。

如果有人知道,我想知道为什么它不能与 "command": "tsc"一起工作,即使在该命令行的 tasks.json 文件中的注释也是如此:

// The command is tsc. Assumes that tsc has been installed using npm install -g typescript

最佳答案

我相信您应该像这样更改 args 命令。 请注意,我将命令更改为指向本地 tsc 版本,但这并不重要。重要的东西在 args 选项中:["-p", "."]

{
    "version": "0.1.0",
    "command": "${cwd}/node_modules/.bin/tsc.cmd",
    "isShellCommand": true,
    "showOutput": "silent",
    "args": ["-p", "."],
    "problemMatcher": "$tsc"
}

关于typescript - Visual Studio Code 未编译所有 *.ts 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36643684/

相关文章:

Visual Studio Code、gcc、Mac 的 C/C++ 扩展 : "variable uint32_t is not a type name"

javascript - 使用索引作为键初始化对象数组

html - 如何在DIV中获取按钮而不调用<div>点击事件

visual-studio-code - 是否可以从 VSCode 中的外部 js lib 获取提示?

java - VS代码无法读取java文件

android-studio - flutter 有必要安装 Android Studio 还是可以用什么来代替 android studio?

javascript - 如何访问 .find 方法中的索引

javascript - 如何在 React with Typescript 中使用 Material UI 自定义变体

javascript - 使用firebase云函数监听后台变化

javascript - 在 Visual Code 中筛选/排序 IntelliSense 建议