angularjs - Documenting Javascript code in VSCode for Intellisense - Stack Overflow

I'm trying to get proper Intellisense suggestions for my javascript code in Visual Studio Code. In

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?

Share Improve this question asked May 2, 2015 at 10:03 Mr. WonkoMr. Wonko 7301 gold badge9 silver badges20 bronze badges 6
  • 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
 |  Show 1 more ment

2 Answers 2

Reset to default 4

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;
  1. Type angular on the first line of any javascript file in your open folder.

  2. Notice the word "angular" is underlined and a lightbulb appears.

  1. 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条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信