95

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

1
  • I want the same but I am not on windows, I got the syntax highlighting but how can I setup the autocompletion for any other program that is not running in windows?
    – nacho4d
    Oct 11, 2012 at 2:12

3 Answers 3

107

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.

8
  • Thanks, that was what I was missing.
    – Ryan Lundy
    Oct 1, 2012 at 23:11
  • 3
    Is there a global location where this file can be placed to enable to be referenced from anywhere?
    – Rick Love
    Oct 10, 2012 at 4:45
  • 23
    Is jquery.d.ts provided by JQUERY or custom. If custom, how do we update and keep sync with new version of JQUERY?
    – Nil Pun
    Oct 13, 2012 at 21:13
  • 2
    @Myagdi: For now this is a manual process. Also don't be surprised if there are bugs in the definitions, it's hard to get this right. Anyway, I bet that once TypeScript takes off it will have a way to link from a JS file to a .d.ts and JQuery will be doing that.
    – coudy
    Feb 3, 2013 at 17:31
  • Is not this very wired to use /// at the start of the line!? It will comment the line! Apr 18, 2017 at 10:37
41

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/

2
  • Are these the same definition files as the nu-get packages?
    – Kieran
    May 22, 2013 at 2:06
  • You can do npm install --save-dev @types/jquery or @types/whatever for other packages too Dec 22, 2016 at 16:42
14

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/

1
  • I wonder if there is a way to use jQuery in the Playground.
    – thorn0
    Oct 6, 2012 at 12:36

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.