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 directory 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 $ .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.