我正在尝试为我在 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
上时,参数显示为“any”(而返回值是使用 angular.d.ts 正确推断的)。所以问题的第一部分是:如何在我的函数中注释类型?
问题的第二部分在实际尝试使用该服务时出现:
module.controller( 'MyCtrl', function( backend ) {
backend.getComments( "test" );
} );
我知道 IntelliSense 不理解 Angular 的依赖注入(inject),所以我需要注释 backend
的类型。但是我如何引用该类型呢?
简而言之:如何为第二个代码段中的 backend.getComments()
调用获取正确的 Intellisense,即参数必须是字符串且返回值将是一个的信息ng.IHttpPromise?
最佳答案
这在 TypeScript 中提供悬停提示。不完全是您想要的,但如果他们扩展它以在其他文件中显示它们,那就太好了。
/**
* Change the role of the employee.
* @param {number} x The id of the employee.
*/
tester: (x: number) => number = (x: number) => x * x;
关于javascript - 在 VSCode for Intellisense 中记录 Javascript 代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30000950/