nicholas.rado
nicholas.rado

Reputation: 13

I can't setup jQuery on vscode

I am new to Stackoverflow, this is my very first question ever, I'm not sure how it all works yet, and I hope I will be able to explain my problem correctly. I was trying to use jQuery in vscode, so I installed Node.js, and then followed this tutorial on youtube; I typed npm install tsd -g, then npm install typings --global, and finally typings install dt~jquery --global in my terminal, as the guy in the tutorial said, and eventually the folder: "typings" appeared into project folder. This is the picture of the folder that appeared.

After that, the guy copied the content of the last file, called "index.d.ts", which in my case contained /// <reference path="globals/jquery/index.d.ts" />, into the "plugins.js" file, stored in the JS folder. As you can see, I do not have that folder and that file. What do I have to do? Have I committed a mistake in creating the whole project, or do I have to create a JS folder from scratch? And if so how? I know very little about vscode and jQuery, typescript... I hope someone can help, Thanks in advance.

Upvotes: 1

Views: 5899

Answers (1)

Yehor Androsov
Yehor Androsov

Reputation: 6162

I'll try to explain on file structure similar to yours

structure

With the last command we generated typings folder. Inside typings/globals/jquery/index.d.ts you can see Typescript declarations that will be used for suggestions in VS Code:

enter image description here

Now we need to modify our index.js to use these typings. With arrows I am showing how import works. We add reference path for typings/index.d.ts. typings/index.d.ts just reexports typings from globals/jquery/index.d.ts (see /// <reference path="globals/jquery/index.d.ts" /> inside it).

enter image description here enter image description here

After making this kind of chaining, we can type in our js file and have automatic suggestions

enter image description here

Upvotes: 2

Related Questions