Reputation: 1446
I use PhpStorm and it is giving me warnings when I define a parameter as a type jQuery with JSDoc.
I've tried to configure jQuery as a library, but it didn't seem to work.
This is my code:
/**
* @param {jQuery} $button
*/
function setActive($button)
{
// The code is working fine, but PhpStorm is giving the warning
// "Unresolved function or method addClass()" here.
$button.addClass("active");
// If I try to do this, no warning is displayed.
$("#test").addClass("test");
}
EDIT:
Some methods appear in the intellisense (I'm not sure why), but unfortunately addClass
isn't one of them.
Upvotes: 1
Views: 415
Reputation: 815
Turns out the Typescript for jQuery uses an Uppercase J so JQuery
instead of jQuery
.
Changing the jsdoc like so fixes this issue.
/**
* @param {JQuery} $button
*/
Otherwise the lowercase jQuery
may be enabled by creating a very simple typescript file somewhere in your project.
For example your file could be named jquery.d.ts
and have the following content.
/**
* Must have the @types/jquery typescript installed
* either via PHPStorm -> Javascript -> Libraries
* or `npm i @types/jquery`
*/
interface jQuery<TElement = HTMLElement> extends JQuery {}
Upvotes: 1
Reputation: 93728
Try adding JQuery typings (either via Settings | Languages & Frameworks | JavaScript | Libraries, TypeScript Community Stubs or by running npm i @types/jquery
in project dir) - this should solve the issue:
Upvotes: 3