Using jQuery in TypeScript

As somebody who mainly develops in C# I do miss strong typing when using JavaScript. So I’ve started to use TypeScript which solves this. But let’s face it, this would be of little use without jQuery (and other frameworks). So here’s the steps to get jQuery running with TypeScript.

  1. If you have already installed TypeScript, grab the latest VS2012 integration from http://www.typescriptlang.org/
  2. Next up, create a new project, navigate to Other Languages | TypeScript and create a new TypeScript project
  3. From the References section in the solution explorer, right mouse click and select Manage NuGet Packages and search for jquery.TypeScript.DefinitelyType and install – this will install a .ts file which includes the jQuery TypeScript definition to allows us to work with code completion
  4. Now either from NuGet, install jQuery or download from http://jquery.com/
  5. To reference the jQuery TypeScript file put /// at the top of the app.ts file, this will allow VS2012 to reference the types in the .ts file
  6. You’ll need to add a script to the default.htm file

Now we’ve got jQuery up and running in TypeScript.

Note: One problem I found on one of my machines was the code complete didn’t work for TypeScript, reading up on this on it appeared (as suggested in one of the posts) that MySQL Connector Net 6.6.5 was causing the problem. Open Control Panel | Programs | Programs and Features, location My SQL Connector 6.6.5 if its installed. Right mouse click on it and select Change and remove the Visual Studio Integration.