首页 文章

在Visual Studio Code中编译typescript的正确tasks.json配置是什么?

提问于
浏览
1

使用 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

3 回答

  • 2

    我有同样的问题 . 它是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"
    }
    
  • 8

    我一直在努力,直到我理解npm是如何在我的Windows笔记本电脑上安装typescript 1.5 beta(或不是) .

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

    • 卸载打字稿的当前版本(对我来说,这是版本1.4.1)

    npm uninstall -g typescript

    • 安装1.5.1-beta版

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

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

    • 将此添加到tasks.json文件:“command”:“C:\ Users \ Bob.Chiverton \ AppData \ Roaming \ npm \ tsc.cmd”,

    现在重新尝试ctrl-Shift-B .

    -Bob

  • 4

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

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

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

相关问题