Ric*_*uhr 3 javascript macos typescript visual-studio-code
微软刚刚发布了适用于Mac OS X平台的新Visual Studio代码.它支持TypeScript,因为它可以获得TypeScript代码的自动完成和错误报告.
我的问题:我们如何从Visual Studio Code中编译TypeScript文件(以生成相应的JavaScript文件)?我已按照推荐创建了一个默认的tsconfig.json文件,只有{},并尝试调用shift + command + B但这不会产生更新的JavaScript文件.
您需要设置一个任务来执行此操作.
如果因为我坐在使用不同的操作系统时我得到的快捷方式有点错误,我会提前道歉.对于使用Windows的任何人来说,它将是CTRL- 我认为OSX版本仅仅意味着使用CMD.
如果按CTRL+ SHIFT+ P,则会出现一个操作菜单,允许您搜索所有命令.
类型Configure Task Runner.如果您还没有,则会在设置文件夹中为您创建tasks.json文件.否则,它将打开现有的tasks.json文件.
您可以取消注释内置的TypeScript任务 - 它看起来像这样(我的主文件是app.ts,此文件中的默认值是HelloWorld.ts):
// A task runner that calls the Typescipt compiler (tsc) and
// Compiles a HelloWorld.ts program
{
"version": "0.1.0",
// The command is tsc.
"command": "tsc",
// Show the output window only if unrecognized errors occur.
"showOutput": "silent",
// Under windows use tsc.exe. This ensures we don't need a shell.
"windows": {
"command": "tsc.exe"
},
// args is the HelloWorld program to compile.
"args": ["app.ts"],
// use the standard tsc problem matcher to find compile problems
// in the output.
"problemMatcher": "$tsc"
}
Run Code Online (Sandbox Code Playgroud)
然后,您可以使用CTRL+ SHIFT+ 按需执行此任务B.
如果您定义了多个任务,则可以使用CTRL+ E和键入task(注意"任务"之后的空格),它将为您提供所有任务的列表供您选择.
你的手不需要离开键盘就可以了!
最后......如果你仍然什么都没有,请检查窗口底部的这个图标,因为你可能有编译错误......(下面的图标显示一个错误 - 在编辑器中点击它以获取详细信息).
