How do I get the TypeScript description file for a specific jQuery version, for example 3.2.1?

I am new to TypeScript and am still trying to figure it out. I have a visual studio project that uses jQuery version 3.2.1 and I would like to make TypeScript type definitions available to my project.

It appears from the internet that the authoritative source for these types of definitions is https://github.com/DefinitelyTyped/DefinitelyTyped

On this page I read

npm
This is the preferred method. This is only available to TypeScript 2.0+ users. For example:

npm install --save-dev @ types / node

I think I just need to type npm install --save-dev @types/jquery

to get the jquery type definition file loaded via npm. But then I asked myself, "Hmm, I'm wondering which version of jquery will have a type definition file if everyone is typing the same command regardless of jquery version. So I went to the npm site to check and weirdly said

This package contains type definitions for jQuery 1.10.x / ( http://jquery.com/ ).

the last update was "Last updated: Sat 11 Mar 2017 00:13:28 GMT".

So, something weird, why was there the latest npm module update for jquery 1.10.x? And why is the latest jquery type def for npm for such an old jquery version? 2.0, maybe 1.10.x? So my guess is that maybe these types of defs are the latest and greatest, and someone who maintains the npm package just doesn't update the summary? But how can I confirm this? I loaded the module and tried to distinguish from which version of jquery the defs type was using but couldn't tell for sure.

So here's my question. How does one get the TypeScript definition file for a specific version of JQuery, ex 3.2.1?

+3


source to share


3 answers


The types you are currently getting are the most recent version of types for jQuery.

There was no change between 1.10.x and 2.0.x, so type definitions work for both.



There's a GitHub issue where someone is requesting new definitions for jQuery 3.x. Unfortunately, no one volunteered to add type definitions for later versions of jQuery, so they will remain in those older versions until someone does.

+1


source


Hi a little late, but this is what I found after I looked in the index.d.ts file, the comment on the first line contains the compatible JQuery version.

npm install @types/jquery@1.x

will provide you with jQuery 1.x definitions



npm install @types/jquery@2.x

will provide you with the JQuery 2.x definitions

npm install @types/jquery@3.x

will provide you with the JQuery 3.x definitions

+5


source


You can print the entire version of a specific npm package using one of these two commands:

npm view package-name versions

OR

npm i package-name@whatever

(you will get an error, but it will print all available versions)

Then just install the specific version by running:

npm i package-name@version


So, for the jquery types you ran:

npm view @types/jquery versions

You see all versions (currently the latest version is 2.0.41). You install a specific version:

npm install --save-dev @types/jquery@2.0.41

+2


source







All Articles