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 ments from the backend</summary>
/// <param name="post" type="string">Post to retrieve ments 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 es 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?
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 ments from the backend</summary>
/// <param name="post" type="string">Post to retrieve ments 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 es 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?
-
2
have you tried typing
//**
then hit enter? – John Papa Commented May 3, 2015 at 14:53 -
1
Yes, I'm aware I can do multiline ments using
/**
, but the important part of the question is how do I structure my ments so Intellisense parses them? – Mr. Wonko Commented May 3, 2015 at 19:13 - did you end up solving this? I'm only getting autopletion for stuff that i require(), but it won't work if i take an object that i require and for example expose it in module.exports, and then reference this variable in another file – Zaky German Commented Dec 30, 2015 at 13:26
- No, did not end up solving it. – Mr. Wonko Commented Dec 30, 2015 at 20:41
- 1 A year later, but ... did you get anywhere with this? – Phil Ricketts Commented Dec 13, 2016 at 14:17
2 Answers
Reset to default 4This 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;
Type angular on the first line of any javascript file in your open folder.
Notice the word "angular" is underlined and a lightbulb appears.
- You have the option of adding a reference to angular. Do this.
Notice a new folder has appeared with this reference in it. You will now have intellisense.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744208332a4563213.html
评论列表(0条)