Visual Studio Javascript Intellisense - 选项对象

时间:2013-02-24 00:02:51

标签: visual-studio visual-studio-2012 javascript-intellisense vsdoc

我想在Visual Studio中获得我在方法调用中使用的选项对象的Intellisense支持。

在Javascript中使用catch-all选项对象配置对函数的调用是很常见的 - 例如jquery的Ajax调用使用:

$.ajax(settings);

设置只是一个对象:

$.ajax({
    url: '/blah',
    data: { stuff: 1 },
    method: 'POST',
    // etc
});

虽然它是一个隐式对象,但属性遵循特定的类。通常当你有类似这样的东西时,这对于Intellisense /描述代码很重要,但对于代码不起作用,你可以把它放在-vsdoc.js文件中。但是我如何让Intellisense为这个对象做好准备呢?

我查看了jquery-vsdoc.js的一个例子,因为它是由微软提供的 - 无济于事。在一种情况下,他们只需将其键入“对象”,另一种情况下根本不记录它。

我试过这个例子 - 在fillTable.js:

function fillTable(options) {
    /// <param name="options" type="FillTableOptions">Options to fill table</param>

在fillTable-vsdoc.js中:

function FillTableOptions() {
    /// <field type="String">Id property</field>
    this.idProp = 'Id';

但我得到的智能感知就是类型是FillTableOptions - 当我创建对象时,我在选择属性时没有获得Intellisense帮助。

那么,我如何获得Intellisense支持这样的对象的属性?

1 个答案:

答案 0 :(得分:2)

我不知道如何在TypeScript之外的对象参数上获得 true Intellisense支持...但是,您可以在一定程度上格式化参数文档节点。

例如,您可以在“类型”属性中输入您喜欢的任何文本,只要它是连续的文本块(不包含任何空格或中断字符)。

实施例。 1:自定义类型注释。

function where(collection, evaluator) {
    /// <summary>
    /// Equivalent to a WHERE clause.
    /// </summary>
    /// <param name="collection" type="array||object">Accepts an array or associative array (object).</param>
    /// <param name="evaluator" type="function(key,value,index)">Applied to each element of the @collection to determine which elements to return.</param>
    /// <returns type="array||object" />
}

实施例。 2:多行参数文档(&#10;是一个新行)。

function modal(options) {
    /// <summary>
    /// Displays a modal window.
    /// </summary>
    /// <param name="options" type="object||string">
    /// &#10;If a string is passed in, will be treated as @heading.
    /// &#10;
    /// &#10;* heading {string} The heading text.
    /// &#10;? content {string} The text content; overridden by @htmlContent.
    /// &#10;? htmlContent {string} Use when HTML content is desired; overrides @content.
    /// &#10;? settings {object} FancyBox.js settings.
    /// </param>
}

这不会像TypeScript那样为您提供真正的对象参数Intellisense,但它可以让您更好地控制注释的样式,并有助于减少歧义。