Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to reference jQuery (intellisense) in a typescript file (VS2015)

I have a lot of javascript plugins and libraries in my ASP.NET MVC project,
that I want to convert to typescript.

Questions:

How to reference jQuery in ts files?

I get this error below when I manually build the ts file using tsc

myfile.ts(170,4): error TS2304: Cannot find name 'jQuery'.
myfile.ts(172,1): error TS2304: Cannot find name '$'.
myfile.ts(173,2): error TS2304: Cannot find name '$'.

like image 965
Legends Avatar asked Jan 05 '23 13:01

Legends


1 Answers

  1. Install Node.js if you haven't already
  2. Open the command line (cmd.exe)
  3. cd to your project root directory
  4. Execute npm install @types/jquery

Now under node_modules you will find the "index.d.ts" typescript definition file for jQuery.

node_modules/@types/jquery/index.d.ts


5. Drag and Drop the file on the top of your opened typescript file "yourFile.ts"

/// <reference path="../../../node_modules/@types/jquery/index.d.ts" />
....
... your typescript code here

Now you will have intellisense for jQuery and $.

like image 161
Legends Avatar answered Jan 11 '23 18:01

Legends