admin管理员组

文章数量:1356236

I have an error in the declaration file of angular:

TS2304: Cannot find name 'JQueryStatic'.

I do have the typings of jquery installed. There, JQueryStatic is declared as an interface.

How can I solve it?

I have an error in the declaration file of angular:

TS2304: Cannot find name 'JQueryStatic'.

I do have the typings of jquery installed. There, JQueryStatic is declared as an interface.

How can I solve it?

Share Improve this question asked May 11, 2017 at 16:47 AlonAlon 12k28 gold badges103 silver badges172 bronze badges 4
  • Please show us your code – Alon Eitan Commented May 11, 2017 at 16:48
  • 1 are you using SignalR by any chance? – Kumar Nitesh Commented May 11, 2017 at 16:51
  • @Knitesh no, I'm not. – Alon Commented May 11, 2017 at 16:55
  • Really need some code and context here. "When" do you get this error? In your IDE? When you run the code? Where did you install the typings? In node_modules/@types ? Because then you also need to add it in your tsconfig.: "typeRoots": ["node_modules/@types/"] – therebelcoder Commented May 11, 2017 at 16:58
Add a ment  | 

2 Answers 2

Reset to default 8

Same problem with me. (Angular 6)

Here's how I resolved it:

Step 1: npm install jquery

Step 2: npm install --save-dev @types/jquery

Step 3: Go to file angular.json Add code below in scripts: [...]

"node_modules/jquery/dist/jquery.min.js"

Step 4: Go to file src/typings.d.ts Add code below

import "jquery";

declare var $: JQueryStatic;
declare var jQuery: JQueryStatic;

Now you can use $ or jQuery inside the typescript ponent.

I fixed it by adding a reference to jquery:

///<reference path="../jquery/index" />

本文标签: javascriptangular39s definelytyped doesn39t recognize JQueryStaticStack Overflow