Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to include jquery with typings #231

Closed
quanterion opened this issue Jan 17, 2016 · 13 comments
Closed

How to include jquery with typings #231

quanterion opened this issue Jan 17, 2016 · 13 comments

Comments

@quanterion
Copy link

I added jquery to this starter using instructions from this link #215
But I have TypeScript errors like this:
TS2339: Property 'ajax' does not exist on type 'cssSelectorHelper'. or
TS2339: Property 'mousedown' does not exist on type 'ElementFinder'.
In all places where I access $ variable

I have tried adding jquery.d.ts to files section of tsconfig.json (just after line "typings/main.d.ts"), but the problem persist. How to fix it?

@PatrickJS
Copy link
Owner

typings install jquery --save

@quanterion
Copy link
Author

I got an error:
typings ERR! message Unable to find "jquery" in the registry. Maybe you want to install ambient definitions using "--ambient"? Alternatively, if you can contribute this typing, please help us out: https://github.com/typings/registry

PS: I downloaded jquery.d.ts manually from DefinetlyTyped and put this files to typings folder

@quanterion
Copy link
Author

Should I use an ambient option? I have read in blakeembrey blog, that he advises against using ambient modules http://blakeembrey.com/articles/2015/11/state-of-typescript-packaging/

@abdulhaq-e
Copy link
Contributor

Look at the end of jquery.d.ts, change the exported var from $ to jQuery, that should solve your problem.

@blakeembrey blakeembrey removed their assignment Jan 17, 2016
@blakeembrey
Copy link
Contributor

@RemKolomna can you share what you're doing right now. To install from DefinitelyTyped, you can do typings install jquery --ambient --save - it's better to use non-ambient modules where available, but jQuery has already been typed so you might as well make use of it 😄

As for the additional issues, I know Angular has some binding so the global $ so you might have to do something there. If you can provide a link I can quickly review what you've done, that'll make it easier.

@abdulhaq-e
Copy link
Contributor

@blakeembrey

As for the additional issues, I know Angular has some binding so the global $ so you might have to do something there. If you can provide a link I can quickly review what you've done, that'll make it easier.

Indeed it does, I solved it by changing L3200 from:

export = $;

to

export = jQuery;

The problem with this solution is, if jQuery is included as a requirements in the typings file then typings install will reset the file.

@blakeembrey
Copy link
Contributor

Awesome, makes sense. What we can do in Typings is turn jQuery into an external module and allow installation, just need someone to maintain that 👍 As for the reset, you don't have to use Typings to install it. I usually make a custom_typings/ directory and put stuff in there, which I then include in tsconfig.json. Typings itself follows this: https://github.com/typings/typings/blob/master/tsconfig.json. If you do want to use Typings, you can do typings install file:custom_typings/jquery.d.ts --ambient --save for now.

@quanterion
Copy link
Author

Thanks! I added jquery to custom_typings, change to export = jQuery; and everything is ok now!

@qSoft
Copy link

qSoft commented Sep 6, 2016

you should use:

typings install dt~jquery --global

@trsh
Copy link

trsh commented Oct 29, 2016

@qSoft I got:

[default] C:\Projects\xx\yy\typings\globals\jquery\index.d.ts:3227:13
Subsequent variable declarations must have the same type. Variable '$' must be of type 'cssSelectorHelper', but here has type 'JQueryStatic'.
[default] Checking finished with 2 errors

@Neur0mante
Copy link

I'm not using typings anymore, just including "@types/jquery": "^2.0.34" in my package.json file.

@joshwiens
Copy link
Contributor

Did you add the jquery types to your tsconfig as well?

i.e - https://github.com/AngularClass/angular2-webpack-starter/blob/master/tsconfig.json#L19-L26

@Neur0mante
Copy link

Yes, sorry, forgot about that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants