Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot find type definition file for 'jquery'

I just ran an update in NuGet to update my my packages. Afterwards, I can no longer compile and I receive the above error.

The jquery definition file is in my project. But for some reason, the bootstrap definition file can no longer find it.

It's been a while since I worked on this project. I'm pretty sure I had my definition files in a completely different directory before the update. But most of the code and file structure has been created automatically by Visual Studio NuGet packages.

Where are these links or references located so that the definition files can be found properly? I'm very new to TypeScript, so if you can explain in detail or provide links for further reading, it would be appreciated

code and error

file tree


Edit:

I've discovered that these are called Triple-Slash Directives. But that pages doesn't tell me enough to understand this error.

It tells me that <reference types="..."/> should be used for @types packages which is what I believe .d.ts files are. I tried changing the name of jquery.d.ts to index.d.ts. And I've tried including the whole path such as ../jquery/jquery.d.ts. Neither of these worked.

Finally, I found the following line in angular.d.ts:

/// <reference path="../jquery/jquery.d.ts" />

I copied that into the bootstrap index.d.ts and that seemed to fix the error.

But this doesn't make sense to me. First, I'm trying to link to a definition file, not a TypeScript file. So I should be using reference types, not reference path, according to the above article. But reference types does not work. What am I missing here?

The article also says:

Use these directives only when you’re authoring a d.ts file by hand.

I didn't write these files. They came from NuGet and look to be automatically generated. So why do I need to change this?

like image 902
embedded.kyle Avatar asked Feb 01 '17 20:02

embedded.kyle


2 Answers

They came from NuGet and look to be automatically generated.

Don't use nuget for type definitions. NPM is the way to go.

npm install @types/jquery -D 

And then you can:

<reference types="jquery"/>

welcome to the future 🌹

like image 173
basarat Avatar answered Nov 16 '22 19:11

basarat


I found that changing /// <reference types="jquery" /> to /// <reference path="../JQuery.d.ts" /> in jquery.slim.d.ts after installing @types/jquery fixed this issue for me.

like image 39
Z Wu Avatar answered Nov 16 '22 19:11

Z Wu