[@types/jquery] assumes too much about $ and jQuery global variables #68853
Replies: 2 comments
-
Thanks for the discussion about "jquery", some useful links for everyone: Pinging the DT module owners: @leonard-thieu, @borisyankov, @choffmeister, @Steve-Fenton, @Diullei, @tasoili, @seanski, @Guuz, @ksummerlin, @basarat, @nwolverson, @derekcicerone, @AndrewGaspar, @seikichi, @benjaminjackman, @JoshStrobl, @johnnyreilly, @DickvdBrink, @King2500, @terrymun, @martin-badin, @princefishthrower. |
Beta Was this translation helpful? Give feedback.
-
I have the same issue. Because of these two lines, typescript is not complaining if I am not importing directly jQuery in a file that is using it and I do not want jQuery to clutter the global namespace. In the old version, our webpack was set up so that it supplied the global jQuery variable, but right now we are trying to change that, and it is really really hard to hunt down all the files, where jQuery was used globally. |
Beta Was this translation helpful? Give feedback.
-
Regarding
@types/jquery@3.5.29
I'm workin on a very big and old project with multiple versions of jQuery. Some of the old ones (v1 and v2) are handled by rails and injected automagically in the global scope.
However, in the more recent features that are implemented with Wevpack+Typescript we use import jQuery v3 from node_modules. We
import $ from 'jquery'
and use it locally in some file, we do not export this to the global scope. However, typescript assumes that it is available everywhere and it is causing issues.The culprit must be these lines
DefinitelyTyped/types/jquery/misc.d.ts
Lines 7336 to 7337 in 5dddaaa
IMHO the types should not assume jQuery is in the global scope by default. It should be the user who declares these vars manually in their
globals.d.ts
provided they export it:In our project is messing up all files where we call
$
from the global scope expecting it to be v1 but webpack and the editor are throwing type errors assuming it's v3.Here's an issue I opened, believing it was a TS error, with some additional context: microsoft/TypeScript#57555
Beta Was this translation helpful? Give feedback.
All reactions