相关疑难解决方法(0)

Visual Studio代码:编译typescript模块

我刚刚下载了新的Visual Studio Code,我的第一印象非常积极.对于打字稿,intellisense工作得很漂亮.

但是,有一个奇怪的问题:VS Code似乎无法编译typescript模块.

这段代码:

/// <reference path="../definitions/react.d.ts"/>

import React = require("react");
Run Code Online (Sandbox Code Playgroud)

在cmd上编译完全正常

tsc --module commonjs main.ts

但在VS Code中,第二行以红色突出显示,编辑抱怨:

除非提供"-module"标志,否则无法编译外部模块

当然,任何使用模块的打字稿代码都必须使用此标志进行编译.但是如果IDE知道模块的用法,为什么不设置标志呢?没有模块的打字稿代码在保存时编译,没有问题.

我想我错过了一些编译器设置配置文件.有这样的事吗?我在哪里可以找到它?

UPDATE

我添加了tsconfig.json文件:

{
    "compilerOptions": {
        "target": "ES5",
        "module": "commonjs",
        "sourceMap": true
    }
}
Run Code Online (Sandbox Code Playgroud)

这实际上消除了错误.不幸的是,IDE不再编译我的代码.起初我以为config.json只会使错误消息静音,但它确实不止于此.Intellisense现在可以在示例文件中使用.如果我键入React自动完成被触发并且显然知道React,因为显示了有意义的建议.

现在,为什么VS Code没有将文件编译为js?我已经尝试配置任务运行器来完成这项工作,但它似乎不起作用:

{
    "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"
    }, …
Run Code Online (Sandbox Code Playgroud)

compilation typescript visual-studio-code

30
推荐指数
3
解决办法
2万
查看次数

如何在Visual Studio Code中保存`go fmt`?

如何go fmt在保存时运行Visual Studio代码(或Go编程语言扩展)(或其他工具/命令)?甚至自动保存?

更新:此时 它正在VSCode中完美地工作; 只需要在.vscode目录中添加一些配置文件(我使用这些).

go visual-studio-code

7
推荐指数
2
解决办法
1万
查看次数

在 Visual Studio Code 中对键绑定运行 npm 命令

我想使用 webpack 打包保存 js 文件。

这最好使用 webpack watch 来完成。但是无所谓...

下面的答案是我谷歌搜索的结果,我希望在某些时候对某人有用。

key-bindings npm visual-studio-code

4
推荐指数
2
解决办法
2608
查看次数