简体   繁体   中英

WebStorm code completion for Node shows too many options

I've created a small project with NodeJS and TypeScript code. Installed the type definition files there (tsd install node). The code starts with these lines:

var http = require('http'); var server = http.createServer(...)

When I open this code in WebStorm 11 it shows me hundreds of options in a context-sensitive help window when I hit CTRL-Space after http.

I tried adding /// <reference path="typings/node/node.d.ts" /> as the first line, downloaded and installed DefinitelyTyped community stub, but it still shows tons of options for the http object.

When I open the same file in Visual Studio Code, it shows me a short list of API related to Node's http module. How to teach WebStorm to be smarter with code completion?

I tried adding /// as the first line, downloaded and installed DefinitelyTyped community stub, but it still shows tons of options for the http object.

This is because you are using var/require . This means that webstorm is being heuristic in its suggestions. You should use import/require to narrow it down to just what is actually declared for the http module :

import http = require('http');
var server = http.createServer(...)

More on import : https://basarat.gitbooks.io/typescript/content/docs/project/modules.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM