Search code examples
javascriptnode.jswebstormtype-hinting

Coding Assistance or Type Hints in WebStorm for event handlers


I'm sure this is a frequently asked question, but I couldn't find an answer searching on my own.

I'm learning Node using WebStorm as my IDE. I have enabled Coding Assistance as described at this answer here.

And it starts to work:

enter image description here

Now further down as I start hooking up event handlers for my objects. In this case, a simple event handler for an incoming connection on a net.Server object. But it has no idea about the type of the object expected by the callback function passed to server.on. So as soon as I type . to bring up the coding assistance dialog for clientSocket, it can only show me the common methods for Object, and not the net.Socket type that the object is really expected to be.

enter image description here

I get that JavaScript is weakly typed and that it would be a challenge for any IDE to auto identify the type of such variables as the developer is typing.

If there is a way WebStorm could be configured to do that, then great. Otherwise, is there some simple annotation or comment I could add to the code such that the IDE is given a hint as to a variables actual object type such that coding assistance would work in this case?


Solution

  • Bottom line. WebStorm just doesn't do intellisense very well with a language such as JavaScript that isn't strongly typed.

    I switched to VS Code and set it up for TypeScript and it just works. Then I tried out Visual Studio 2017 with its node support. Wow - everything works with Typescript out of the box.