簡體   English   中英

如何在 typescript 文件 (VS2015) 中引用 jQuery (intellisense)

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

我的 ASP.NET MVC 項目中有很多 javascript 插件和庫,
我想轉換為打字稿。

問題:

如何在 ts 文件中引用 jQuery?

當我使用tsc手動構建 ts 文件時,出現以下錯誤

myfile.ts(170,4):錯誤 TS2304:找不到名稱“jQuery”。
myfile.ts(172,1):錯誤 TS2304:找不到名稱“$”。
myfile.ts(173,2):錯誤 TS2304:找不到名稱“$”。

  1. 如果你還沒有安裝Node.js
  2. 打開命令行(cmd.exe)
  3. cd到你的項目根目錄
  4. 執行npm install @types/jquery

現在在 node_modules 下,您將找到 jQuery 的“index.d.ts”打字稿定義文件。

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


5. 將文件拖放到打開的打字稿文件“yourFile.ts”的頂部

/// <reference path="../../../node_modules/@types/jquery/index.d.ts" />
....
...你的打字稿代碼在這里

現在你將擁有jQuery$的智能感知。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM