I'm trying to get proper Intellisense suggestions for my javascript code in Visual Studio Code. In particular, I have the following AngluarJS service:
/// <reference path="definitelytyped/angularjs/angular.d.ts" />
var module = angular.module( 'testApp', [] );
module.factory( 'backend', function ( $http ) {
return {
"getComments": function HoverHereToSeeType( post ) {
/// <summary>Retrieves comments from the backend</summary>
/// <param name="post" type="string">Post to retrieve comments for</param>
return $http.get( "/rest/" + post );
}
};
} )
I thought I should be using XML Documentation Comments, but they don't seem to work - when I hover over HoverHereToSeeType
the parameter is shown as "any" (while the return value is properly inferred using angular.d.ts). So the first part of the question is: How do I annotate types in my functions?
The second part of the question comes up when actually trying to use the service:
module.controller( 'MyCtrl', function( backend ) {
backend.getComments( "test" );
} );
I get that IntelliSense doesn't understand Angular's dependency injection, so I'll need to annotate backend
's type. But how do I reference that type?
In short: How do I get proper Intellisense for the backend.getComments()
call in the second snippet, i.e. the information that the parameter has to be a string and the returned value will be an ng.IHttpPromise?
You can trigger IntelliSense in any editor window by typing Ctrl+Space or by typing a trigger character (such as the dot character (.) in JavaScript).
Open the JavaScript code file in Text Editor, then use shortcut Control + Alt + N (or ⌃ Control + ⌥ Option + N on macOS), or press F1 and then select/type Run Code , the code will run and the output will be shown in the Output Window.
IntelliSense# Visual Studio Code's JavaScript IntelliSense provides intelligent code completion, parameter info, references search, and many other advanced language features. Our JavaScript IntelliSense is powered by the JavaScript language service developed by the TypeScript team.
This provides hover hints in TypeScript. Not exactly what you want, but if they extend this to show them in other files, it would be great.
/**
* Change the role of the employee.
* @param {number} x The id of the employee.
*/
tester: (x: number) => number = (x: number) => x * x;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With