Reputation: 6307
Im using VSCode and in it made 2 files index.html and app.js I created this function
function hello(){
console.log("hello");
}
hello();
when I hover over hello function the text appear on hovering, function() : void so how IDE determines that what is return type of function although its js file not ts file still it showing return and data type, how this happens, what is this thing that causes it
Upvotes: 1
Views: 685
Reputation: 5802
Well, I am assuming that the team behind Visual Studio does some analysis on the javascript code that you write. In the case of your method, it's easy to see the return type should be void. Maybe it can do more complex analysis as well, you could find out by returning a method returning an integer (statically) or even an object. This is part of what they call IntelliSense in Visual Studio.
Even when you are programming using javascript instead of typescript, you can still determine what Type a variable is. Typescript gives this an explicit mention, e.g: let name : String = "JD";
. But even in plain Javascript you are dealing with types, even when you do not give them an explicit mention. You can test this with, for example, the following code.
var name = "JD";
console.log(typeof name); // logs "string"
I think that explaining exactly how IntelliSense does this would be beyond the scope of this answer and I fear that I will not be able to give an adequate answer either. Though there are a few posts on stackoverflow which aim to answer this, or seem to link to further resources anyway.
Upvotes: 1