Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get TypeScript definitions file for a particular version of Jquery, ex 3.2.1?

I'm new to TypeScript and still trying to figure it out. I have a sample visual studio project that uses jquery version 3.2.1 and I'd like to make the TypeScript type definitions available to my project.

From the internet it appears that the authoritative source for these type definitions is https://github.com/DefinitelyTyped/DefinitelyTyped

On that page I read

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

npm install --save-dev @types/node

So it would seem I just need to type npm install --save-dev @types/jquery to get the jquery type definition file downloaded via npm. But then I asked myself, hmm, I wonder what version of jquery those the type definition file will be for if everyone is typing the same command regardless of jquery version. So I went over to the npm site to check and oddly it said

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

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

So that just seems odd, why would there be a recent update to an npm module that is for jquery 1.10.x? And why would the latest version of the jquery type def on npm be for such an old version of jquery? 2.0 maybe but 1.10.x? So I'm guessing that perhaps these type defs are the latest and greatest and whoever is maintaining the npm package just isn't updating the summary? But how can I confirm that? I downloaded the module and tried to discern from that what version of jquery the type defs were for but was unable to tell for sure.

So here's my question. How does a person get TypeScript definitions file for a particular version of Jquery, ex 3.2.1?

like image 261
RonC Avatar asked Dec 03 '22 22:12

RonC


2 Answers

You can print all version of specific npm package using one of these two commands:

npm view package-name versions

OR

npm i package-name@whatever (You'll get an error, but it prints all available versions)

Then just install specific version by running:

npm i package-name@version


So for jquery types you would run:

npm view @types/jquery versions

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

npm install --save-dev @types/[email protected]

like image 42
Erik Cupal Avatar answered Dec 09 '22 13:12

Erik Cupal


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

npm install @types/[email protected] will get you JQuery 1.x definitions

npm install @types/[email protected] will get you JQuery 2.x definitions

npm install @types/[email protected] will get you JQuery 3.x definitions

like image 169
DaMightyMouse Avatar answered Dec 09 '22 13:12

DaMightyMouse