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 '$'.
cd
to your project root directorynpm 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 $.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With