javascript - Cách sử dụng jsdoc để khai báo loại biến nodejs trong visual studio code?
Ví dụ, điều này là đúng:
const net = require('net');
const Socket = net.Socket;
/**@type {Socket} */
var s;
s.setTimeout(0);
Nhưng những cái này không đúng:
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;
Vậy, làm thế nào tôi có thể khai báo một Socket mà không cần thêm const Socket=net.Socket;