Node 的 WebStorm 代码完成显示选项太多
WebStorm code completion for Node shows too many options
我用 NodeJS 和 TypeScript 代码创建了一个小项目。在那里安装了类型定义文件(tsd install node)。代码以这些行开头:
var http = require('http');
var server = http.createServer(...)
当我在 WebStorm 11 中打开此代码时,当我在 http 后按 CTRL-Space 时,它会在上下文相关帮助 window 中显示数百个选项。
我尝试添加 /// <reference path="typings/node/node.d.ts" />
作为第一行,下载并安装了 DefinitelyTyped 社区存根,但它仍然显示了 http 对象的大量选项。
当我在 Visual Studio 代码中打开同一个文件时,它会显示与 Node 的 http 模块相关的 API 的简短列表。如何通过代码完成让 WebStorm 变得更聪明?
I tried adding /// as the first line, downloaded and installed DefinitelyTyped community stub, but it still shows tons of options for the http object.
这是因为您正在使用 var/require
。这意味着 webstorm 在其建议中 heuristic。您应该使用 import/require
将其缩小到 正是为 http 模块 实际声明的内容:
import http = require('http');
var server = http.createServer(...)
关于 import
的更多信息:https://basarat.gitbooks.io/typescript/content/docs/project/modules.html
我用 NodeJS 和 TypeScript 代码创建了一个小项目。在那里安装了类型定义文件(tsd install node)。代码以这些行开头:
var http = require('http');
var server = http.createServer(...)
当我在 WebStorm 11 中打开此代码时,当我在 http 后按 CTRL-Space 时,它会在上下文相关帮助 window 中显示数百个选项。
我尝试添加 /// <reference path="typings/node/node.d.ts" />
作为第一行,下载并安装了 DefinitelyTyped 社区存根,但它仍然显示了 http 对象的大量选项。
当我在 Visual Studio 代码中打开同一个文件时,它会显示与 Node 的 http 模块相关的 API 的简短列表。如何通过代码完成让 WebStorm 变得更聪明?
I tried adding /// as the first line, downloaded and installed DefinitelyTyped community stub, but it still shows tons of options for the http object.
这是因为您正在使用 var/require
。这意味着 webstorm 在其建议中 heuristic。您应该使用 import/require
将其缩小到 正是为 http 模块 实际声明的内容:
import http = require('http');
var server = http.createServer(...)
关于 import
的更多信息:https://basarat.gitbooks.io/typescript/content/docs/project/modules.html