Javascript library load order problems

I'm working on a javascript web project that includes no extra libraries or frameworks but jQuery.

I created a project as "Static Web".

In "Settings > Languages & Frameworks > JavaScript > Libraries" i added and enabled jquery, and I can confirm it works.

"HTML" is also enabled.

However, inside my document, on $('...').insertBefore(...) it uses the definition from the "HTML" module "DOMCore.js" instead of jQuery.js. Because of this, its giving incorrect warnings about incorrect function arguments.

Is there a way to tell IntelliJ to consider the jQuery library before the HTML library? If not, why is IntelliJ not remembering the type of a jQuery object when it is declared?

Just for clarity sake, this isn't on just .insertBefore(). It also happens on other functions like .find() (which uses EcmaScript6.js>Array.prototype.find)

0
5 comments

The problem is that WebStorm can't resolve JQuery insertBefore() definition because it's created dynamically in JQuery code:

jQuery.each({
appendTo: "append",
prependTo: "prepend",
insertBefore: "before",
insertAfter: "after",
replaceAll: "replaceWith"
}, function( name, original ) {
jQuery.fn[ name ] = function( selector ) {
...

 

So the same-named DOM function is resolved instead

You can try using jquery Typescript community stubs for type resolving: in Settings | Languages & Frameworks | JavaScript | Libraries, press Download..., choose TypeScript Community Stubs, select 'jquery' from the list

 

0

Shouldn't importing the API documentation fix that though?

0

don't understand what you meant to say, sorry

0

If I remove the "HTML" library, it has the correct jQuery function definitions. It is able to parse them b/c the library has Documentation `Settings > Languages & Frameworks > JavaScript > Libraries > jQuery > Documentation URLs`. So it isn't a function definition parsing problem, but an ordering problem.

0

When HTML library is disabled, WebStorm matches method by name only. Such matching has low priority, that's why method is only resolved to

insertBefore: "before"

when no better matches are found

0

Please sign in to leave a comment.