Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mimicking Casting with Visual Studio's JavaScript IntelliSense

I am passing in a jQuery object into a function from another file via an array like the following:

$(document).bind("loadStoreDisplayCallGoals", function(source, urlParams)
{
    var selectedStoreDocument = urlParams["storeDocument"];
}

selectedStoreDocument should be a jQuery object, however Visual Studio Intellisense will never recognize it as such. I tried adding extending selectedStoreDocument with $.extend:

// cast selectedStoreDocument to a jQuery type
$.extend(selectedStoreDocument, $);

However, extending selectedStoreDocument wiped out all of my jQuery methods (.each, .find, etc.).

How can I get selectedStoreDocument to appear as a jQuery object in IntelliSense? Note that I am working in Visual Studio 2010.

like image 997
Peder Rice Avatar asked Jul 26 '11 14:07

Peder Rice


People also ask

How to use JavaScript in Visual Studio IntelliSense?

In Visual Studio, we get IntelliSense support for JavaScript in our markup files ( .html or .aspx) when we include these references using the <script> tag. But what if we are writing pure JavaScript ( .js) files which will later be included in our markups.

How does VS Code IntelliSense work with language services?

VS Code IntelliSense features are powered by a language service. A language service provides intelligent code completions based on language semantics and an analysis of your source code. If a language service knows possible completions, the IntelliSense suggestions will pop up as you type.

Does xrmtoolkit support IntelliSense forms?

If not, XrmToolkit will re/generate them using the older format. XrmToolkit provides both JavaScript and TypeScript files that allow you to have all the intellisense features in Visual Studio for your CRM forms. To learn how to generate these files see the documentation found here .

How do I fix IntelliSense issues in Visual Studio 2015?

Older versions of Visual Studio (prior to VS 2015) didn't have a separate folder and dumped that same information into files in the solution's root folder. In these older versions you can fix Intellisense issues by deleting the Solution's .suo file.


1 Answers

I created a separate file for utility functions, and a second file for the utility functions + VSDoc.

utilities.js:

function castToJQuery(item)
{
    return item;
}

utilities-vsdoc.js:

function castToJQuery(item)
{
    /// <summary>
    ///     1: $(item) - "Casts" the specified item to a jQuery object for the sake of Intellisense
    /// </summary>
    /// <returns type="jQuery" />
    return $("dummy");
}

Now I can call castToJQuery in any of my downstream files to make Visual Studio think a dynamic property is a jQuery object.

var selectedStoreDocument = castToJQuery(urlParams["storeDocument"]);
selectedStoreDocument.find("products");

Visual Studio now works with Intellisense for my dynamic urlParams["storeDocument"].

like image 63
Peder Rice Avatar answered Oct 15 '22 18:10

Peder Rice