10

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?

6
  • 2
    have you tried typing //** then hit enter? Commented May 3, 2015 at 14:53
  • 1
    Yes, I'm aware I can do multiline comments using /**, but the important part of the question is how do I structure my comments so Intellisense parses them? Commented May 3, 2015 at 19:13
  • did you end up solving this? I'm only getting autocompletion 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 Commented Dec 30, 2015 at 13:26
  • No, did not end up solving it. Commented Dec 30, 2015 at 20:41
  • 1
    A year later, but ... did you get anywhere with this? Commented Dec 13, 2016 at 14:17

2 Answers 2

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;
Sign up to request clarification or add additional context in comments.

10 Comments

But I'm writing JavaScript, where commenting with that syntax is apparently not picked up by IntelliSense.
@Mr.Wonko, you're using VSCode, which is not the same as Visual Studio. I've just tried — IntelliSense does work with JSDoc comments and doesn't with Visual Studio's XML comments. (Note that I've tried with JavaScript.)
Yes, I am using VSCode, wasn't that clear from my question? So when you say you just tried, do you mean with VS or with VSCode? Because in VSCode it doesn't work for me.
What. Why doesn't it work that way for me? But still, that's not exactly what I'm after - the deduced type (top line in the popup) still ignores the comment, which is especially important for the return type (and getting auto-completion when working with it).
I have no slightest idea why it doesn't work for you. Maybe you have an idea why Git's pull/push doesn't work for me? (Probably because it is a beta.)
|
0
  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.

Adding reference to Angular

  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.

Typings folder

1 Comment

Thanks, but I'm not looking for Intellisense for the Angular library - I already have that, as evidenced by the <reference> comment - I want it for the code I wrote.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.