如何使用jsdoc在visual studio代码中声明nodejs变量类型?

时间:2018-03-02 01:21:33

标签: javascript typescript visual-studio-code jsdoc

例如,这是正确的:

const net = require('net');
const Socket = net.Socket;
/**@type {Socket} */
var s;
s.setTimeout(0);

但这些不正确:

const net = require('net');
/**@type {NodeJS.Socket} */
var s1; //the type is 'interface Socket' not 'class Socket'

/**@type {typeof net.Socket} */
var s2; //the type is 'interface Socket' not 'class Socket'

/**@type {net.Socket} */  //Can't find namespace "net"
var s3;

那么,如何在没有额外Socket

的情况下声明const Socket = net.Socket;

0 个答案:

没有答案