How do I get jQuery autocompletion in TypeScript?

JqueryTypescript

Jquery Problem Overview


If I'm working in a TypeScript .ts file, what can I do to get jQuery Intellisense/autocompletion when I type the $ character?

(I'm working in an ASP.NET MVC 3 project in VS 2012.)

Jquery Solutions


Solution 1 - Jquery

You need to add a reference to the jQuery definition at the top of your .ts file.

/// <reference path="jquery.d.ts" />

You can find type annotations for jQuery in this sample.

Solution 2 - Jquery

Check out these type definitions for TypeScript: https://github.com/borisyankov/DefinitelyTyped#readme. They're being updated regularly and are more complete than the ones in the examples. On Nuget: http://www.nuget.org/profiles/DefinitelyTyped/

Solution 3 - Jquery

Checklist of things that need to be set up for this to work:

  1. Ensure the TypeScript extension is installed. Check Tools -> Extension Manager and make sure "TypeScript for Microsoft Visual Studio" extension is installed. If it isn't, run the .vsix file found in the TypeScript folder (Program Files\Microsoft SDKs\TypeScript&lt;version>) to install the extension.

  2. Ensure your file references the jquery.d.ts file. You should have a comment at/near the top of your file that looks like this:

> /// <reference path="the/path/to/jquery.d.ts" />

If you need to download it, you can find the jquery.d.ts file as part of the Warship sample at http://www.typescriptlang.org/Samples/

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionRyan LundyView Question on Stackoverflow
Solution 1 - Jquerymohamed hegazyView Answer on Stackoverflow
Solution 2 - Jqueryjvitor83View Answer on Stackoverflow
Solution 3 - JqueryRyan CavanaughView Answer on Stackoverflow