jquery/jquery.d.ts.$ is to ambiguous to be defined as global variable. It can be done easily by user, optionally adding:
declare var $: JQueryStatic;
It causes annoying type warnings, when other definitions use this variable too (they also should not). Having it as an opt-in makes it possible to solve the problem by just not declaring $. For example here a collision with protractor typings which also define $ (again, they should not too) is unfixable without vendor files hacking.
I have a problem with this as well, mostly because in our project we don't have the $ global available and it would trigger a runtime error every time a developer forgot to import jquery and used the global.
I thought Typings would fix this, but it seems it's not able to install the dt jquery definition as non-ambient. As long as the developer will not allow splitting the jquery.d.ts file or removing the global, the only solution is to create and maintain an alternative definition for yourself.
+1
+1
It looks like this was fixed with d1da7ac, but then broken again with 6a556da. Also, is there any reason we should keep the global 'jQuery'? It seems like that is subject to the same issues as '$', though perhaps it is overridden less often.
I still think this should be done. Why was it removed at one point, but then re-added? Can we fix it with tests?
I started doing it, but it turns out (surprise!) that it is a bit more trickier than first envisioned.
Any ideas from the community on how we can get this solved?
Also related: #1564.
For me its a typing error to define something global, without knowledge how the module is actually loaded (globally or not). The public export $ should simply be removed. However I see this is BC break for those, who relied on it and used/use jQuery globally and no other module with same definition.
Is there some issue with that, except the BC break, which is unavoidable to finally fix this?
Btw. I do not really use jQuery anymore, but since I started this issue... :)
It's great you're still chiming in with ideas.
I'm willing to go for the breaking approach, although that also requires a lot of upgrades.
For those, who used it like it is now and were fine with it, it should only require this declaration in global module:
declare var $: JQueryStatic;
Or am I wrong?
I think you're right.
Most helpful comment
+1