Reputation: 1084
I have a node project that uses ws. VSCode knows about the websocket events and functions but if I add something to prototype then it is recognized in suggestions but I can't jump to definition. It say: No definition found for 'setDefaults'. Is there something I need to configure in VScode to work or am I using it wrong?
The source to easy copy:
const WebSocket = require('ws');
WebSocket.prototype.setDefaults = function()
{
console.log("defaults")
}
ws = new WebSocket();
ws.setDefaults()
I also tried Find all references, but it does not find the usage of the method.
Upvotes: 2
Views: 4966
Reputation: 65303
You are running into this known limitation around dynamic properties
One workaround: use jsdocs to declare a new type that includes your extension method:
const WebSocket = require('ws')
/**
* @typedef {{ setDefaults: () => void }} WebSocketExtensions
* @typedef {WebSocket & WebSocketExtensions} ExtendedWebsocket
*
* @type {ExtendedWebsocket}
*/
const ws = new WebSocket();
ws.setDefaults()
Upvotes: 2