Remember that VSCode can only know the type of an object if you explicitly set it some way in the same scope (or use TypeScript). A classic example of this is this example where you have a class and a global variable that is supposed to be of this type but the variable is set inside another scope.
class Test {
foo() { return "bar"; }
}
let unknownTest; // later set to instance of Test
let myTest = new Test(); // immediately set to instance of Test
function makeTest() {
unknownTest = new Test();
}
makeTest();
unknownTest.foo(); // unable to navigate this using F12/Ctrl+Click in VSCode
myTest.foo(); // able to navigate this using F12/Ctrl+Click in VSCode
myTest = 0;
myTest.foo(); // will still navigate even though myTest is now a number
In this case VSCode will let you navigate foo()
from myTest
but not unknownTest
because it has no idea what type it could be as it does not actually run the program to figure out that makeTest()
made it of type Test
.
Also note how easy it is to trick it as JS is untyped you can change the type of any variable like shown in the last two lines. VSCode will still think myTest
is of type Test
.
go to definition
returnsno implementation found
and the otherno implementation found
. But thanks for helping anyway. – Rankinsf12
to go the definition or right click to and selectgo to definition
– Docentno definition found
. – Rankinsctrl + f
to search in the same file orctrl + shift + f
to search for the complete source code – Docentctrl + shift + o
. That is working just fine. No problems with that whatsoever. Neither of them actually allows to simply usectrl + click
at the function name to navigate to function definition/implementation. – Rankins