我正在尝试在 Visual Studio Code 中为我的 javascript 代码获取适当的 Intellisense 建议。特别是,我有以下 AngluarJS 服务:
/// <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 );
}
};
} )
我认为我应该使用XML Documentation Comments,但它们似乎不起作用 - 当我将鼠标悬停在HoverHereToSeeType
参数上时显示为“任何”(而返回值是使用 angular.d.ts 正确推断的)。所以问题的第一部分是:如何在函数中注释类型?
实际尝试使用该服务时会出现问题的第二部分:
module.controller( 'MyCtrl', function( backend ) {
backend.getComments( "test" );
} );
我知道 IntelliSense 不理解 Angular 的依赖注入,所以我需要注释backend
的类型。但是我如何引用该类型?
简而言之:如何为backend.getComments()
第二个片段中的调用获得正确的 Intellisense,即参数必须是字符串并且返回值将是 ng.IHttpPromise 的信息?