How do I get jQuery autocompletion in TypeScript?

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.)


Solution 1:

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:

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:

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\<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/