简体   繁体   中英

vscode does not jump to definition

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.

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()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM