Typescript and jQuery type. Correct way to import jquery type?

Is it possible to include jquery.d.ts and use jQueryStatic type? I need something like

... protected el : jQueryStatic; ... 

No matter how I try, I cannot import the jQueryStatic interface from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/jquery

Many thanks.

Update

 /// <reference path="../../../../defs/jquery.d.ts" /> error TS2304: Cannot find name 'jQuery'. /// <reference path="../../../../defs/jquery.d.ts" /> import {jQuery} from 'jquery'; error TS2305: Module '"jquery"' has no exported member 'jQuery'. 

Update

The working solution was to add a jQuery type, not jQuery.

 /// <reference path="../../../defs/jquery.d.ts" /> ... protected $el: JQuery; 
+7
javascript typescript
source share
1 answer

Based on your code:

 el : jQueryStatic 

Since you used el , I think you had in mind element and thus the correct interface is actually JQuery :

 el : JQuery 

But the question you asked for

You can use typeof to convert a variable to a type. More details: https://basarat.gitbooks.io/typescript/content/docs/project/declarationspaces.html

Update

JQuery (not the case) is declared globally. The following works great:

 import * as $ from 'jquery'; var el:JQuery; 
+8
source share

All Articles