Webstorm: javascript code-complete for dynamically generated class methods Follow
How to annotate a dynamically generated class method in Webstorm so it shows up in the autocomplete?
So far I was able to accomplish similar thing for properties:
/**
* @property prop1
* @property prop2
*/
class MyClass{
//empty class
}
Now if I type "new MyClass().pr"
then Webstorm shows both prop1
and prop2
in the code completion popup.
What is the correct syntax for methods?
It seems @name should do the trick, but Webstorm doesn't recognize it for autocompletion.
Or maybe it's not about annotations but there is a different way of accomplishing that?
Any IDEas?
Here is a quick example of how I generate them:
const methodsConfig = {
method1:"some instructions 1",
method2:"some instructions 2",
}
class MyClass{
generateMethods(){
Object.keys(methodsConfig).forEach(methodName => {
MyClass.prototype[methodName] = (...args) => {
//..further logic here
}
}
}
}
Please sign in to leave a comment.
You ca try using
@property
for methods. Like:Cool, thanks Elena, it now shows the parameters in the code-completion popup which is awesome! That pretty much solves my question.
Just wondering though if it's possible to show it as a method in Webstorm somehow or Webstrom doesn't support that?
While defining a signature this way, it seems it's possible to show either a list of variables or their types but not the both - not a big deal for my case, but still interested if it's possible to get closer here?
Nothing else comes to my mind, sorry:(
Elena Pogorelova
It seems like it just recently stopped working, any ideas?
I've update to the following version recently and deleted .idea file:
WebStorm 2020.1.1
Build #WS-201.7223.93, built on April 30, 2020
Do I need to set any option for it to work again?
it still works for me in WS-201.7223.93:
agh, found the problem: I put a global method between the annotations and the class declaration which broke it:
Removing the method from there fixed the problem!
Thanks for looking into it!