3

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?

4
  • Please show us your code Commented May 11, 2017 at 16:48
  • 1
    are you using SignalR by any chance? Commented May 11, 2017 at 16:51
  • @Knitesh no, I'm not. 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/"] Commented May 11, 2017 at 16:58

2 Answers 2

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 component.

Sign up to request clarification or add additional context in comments.

Comments

1

I fixed it by adding a reference to jquery:

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.