0
votes

I use JSDoc annotations in order to make WebStorm IDE giving autocompletion suggestions. It works fine for builtin types such as number, string, etc. But when it comes to imported types such as net.Socket there is no autocompletion.

My class is written as follows:

var events = require('events');
var net = require('net');
var util = require('util');

/**
 * Create new instance
 * @constructor
 * @extends {events.EventEmitter}
 * @param {net.Socket} socket
 */
function MyClass(socket) {
    events.EventEmitter.call(this);
    /** @type {net.Socket} */
    this.socket = socket;
    this.on('changed', () => console.log('changed'));
}

util.inherits(MyClass, events.EventEmitter);

When I try to use my class I don't get autocompletion for EventEmitter functions nor for the socket member.

What do I need to change?

1

1 Answers

0
votes

try using short names in JSDoc namepaths:

/**
 * Create new instance
 * @constructor
 * @extends {EventEmitter}
 * @param {Socket} socket
 */
function MyClass(socket) {
    events.EventEmitter.call(this);
    this.socket = socket;
    this.on('changed', () => console.log('changed'));
}

This notation works for me - I get completion for Socket and EventEmitter methods