tarlepp tarlepp - 2 months ago 15
AngularJS Question

Angular parameter types on jsdoc

I'm wondering what are the "proper" parameter types on angular specified stuff within jsdoc?

Eg. if I have something like:

/**
* Some comment
*
* @param {WhatHere} $http
* @param {WhatHere} $timeout
*/
function FooBar($http, $timeout) {
}


What are the proper types for those $http and $timeout so that IDE (Web/PhpStorm) can autocomplete those?

Answer

Jetbrains products cannot do this by analyzing the code, there's too much magic in Angular's dependency injection system. However, you can do it by installing a typed library in at least Webstorm and PyCharm (probably PHPStorm and other Jetbrains products as well):

  • Go to Preferences > Languages & Frameworks > JavaScript > Libraries
  • Click the Download… button
  • Select Typescript community stubs in the top-left dropdown (don't worry, it also works for JavaScript)
  • Find angular.js and click the Download and Install button
  • Click the Manage Scopes… button and add angular.js to your project by clicking in the second column and selecting angular.js-DefinitelyTyped.

Now you can annotate your code like this:

/**
 * @param {$http} $http
 * @param {$timeout} $timeout
 */
function FooBar($http, $timeout) {
}

$http $timeout

Note that this trick works for all popular libraries that have a TypeScript community stub available!

Comments