【问题标题】:What is the correct tasks.json config for compiling typescript in Visual Studio Code?在 Visual Studio Code 中编译 typescript 的正确 tasks.json 配置是什么?
【发布时间】:2015-09-02 18:27:07
【问题描述】:

使用Ctrl+Shift+B我添加了一个默认的tasks.json文件并取消了第二个任务运行块的注释。我在目录的根目录中有一个打字稿文件和一个 tsconfig.json。

每次编译时都会收到“错误 TS5023:未知编译器选项“p”。允许我编译打字稿文件的正确定义是什么?子目录下的所有文件都可以一次编译吗?

我尝试将下面的 args 更改为 ["${file}"],这仅允许我编译打开的文件。这行得通。我还从命令提示符运行了 tsc 命令,并且不存在 -p 或 -project 参数。

tasks.json

{
    "version": "0.1.0",

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

    // The command is a shell script
    "isShellCommand": true,

    // Show the output window only if unrecognized errors occur. 
    "showOutput": "silent",

    // Tell the tsc compiler to use the tsconfig.json from the open folder.
    "args": ["-p", "."],

    // use the standard tsc problem matcher to find compile problems
    // in the output.
    "problemMatcher": "$tsc"
}

tsconfig.json

{
    "compilerOptions": {
        "target": "ES5",
        "module": "amd",
        "sourceMap": true
    }
}

VS 代码:v0.30

TypeScript:v1.4

【问题讨论】:

    标签: typescript visual-studio-code


    【解决方案1】:

    我遇到了同样的问题。这是 TypeScript 编译器的错误 PATH 变量。 (尝试在命令窗口中输入tsc -v)。 TypeScript 1.5 版支持tsconfig.json。我的 PATH 变量设置为版本 1。 当我将系统 PATH 变量更改为更新的安装文件夹 (C:\Program Files (x86)\Microsoft SDKs\TypeScript\1.5) 并重新启动 Visual Studio Code 时,一切都很好。 (删除args中的所有条目!)喜欢:

    {
        "version": "0.1.0",
    
        // The command is tsc. Assumes that tsc has been installed using npm install -g typescript
        "command": "tsc",
    
        // The command is a shell script
        "isShellCommand": true,
    
        // Show the output window only if unrecognized errors occur. 
        "showOutput": "always",
    
        // Tell the tsc compiler to use the tsconfig.json from the open folder.
        "args": [],
    
        // use the standard tsc problem matcher to find compile problems
        // in the output.
        "problemMatcher": "$tsc"
    }
    

    【讨论】:

    • 在哪里可以找到 1.5 的安装程序?
    • 安装最新版本:npm install -g typescript,查找已安装文件并设置PATH。或者我做了什么(因为我安装了带有 Typescript 的 Visual Studio):我从 Typescript 网站下载了 Visual Studio 的安装程序。
    • 这个解决方案有帮助吗?
    • 是的,除非我明确使用版本选项,否则使用 npm 它只会安装 1.4。使用 Visual Studio 安装程序更容易,只需将路径添加到 Path 系统变量。
    • 另一种方法是检查版本 tsc -v 是否 >1.5,然后在文件夹 tsc -w 中使用专用的 cmd 窗口查看更新
    【解决方案2】:

    直到我了解 npm 如何在我的 Windows 笔记本电脑上安装 typescript 1.5 beta(或不安装)之前,我一直在挣扎。

    让这个对我有用的关键是:

    1. 卸载当前版本的 typescript(对我来说,这是 1.4.1 版)

      npm 卸载 -g 打字稿

    2. 安装 1.5.1-beta 版

      npm install -g typescript@1.5.0-beta
      (如果您使用的版本不正确,npm 将打印一条错误消息并列出所有版本)

    3. 找到 tsc.cmd 文件 - 在 npm 文件夹下创建。在我的 Windows 8.1 机器上,它存储在: C:\Users\Bob.Chiverton\AppData\Roaming\npm\tsc.cmd

    4. 将此添加到 tasks.json 文件中: "命令": "C:\Users\Bob.Chiverton\AppData\Roaming\npm\tsc.cmd",

    现在重试 ctrl-Shift-B。

    -鲍勃

    【讨论】:

      【解决方案3】:

      对 tsconfig.json 的支持已作为 1.5 版的一部分添加

      路线图: https://github.com/Microsoft/TypeScript/wiki/Roadmap

      提交: https://github.com/Microsoft/TypeScript/pull/1692

      【讨论】:

        猜你喜欢
        • 2016-04-13
        • 1970-01-01
        • 2018-04-14
        • 1970-01-01
        • 2023-01-17
        • 2017-08-02
        • 2019-08-19
        • 2018-03-12
        • 2019-07-24
        相关资源
        最近更新 更多