My PhpStorm / WebStorm IDE keeps telling, that the class
and constructor
are unused for some classes (not for all). I have already set the JavaScript language version to ECMAScript6
and enabled Node.js support in settings. The code in general works fine too. For example ...
File TestClass.js:
module.exports = class Test {
constructor() {
console.log("Test.constructor");
}
test() {
console.log("Test.test");
}
}
File Test.js:
let Test = require("./TestClass");
let inst = new Test();
inst.test();
With this, code inspections keeps telling me:
Unused class TestClass
Unused method constructor
Is there anything wrong or is there a way to suppress the warning? The IDE in general displays no option to suppress this.
Even another problem seems to be, that anonymous classed causes inspection problems too. If I rewrite module.exports = class Test {
to module.exports = class {
even the method test()
inside the class will be marked as unused
. I haven't found a way to prevent this too ...
It seems that I just needed to ask here, to find the answer by myself. ;)
The problem seems to belong to the inline export of the class
. When creating the class
first, and then export
it afterwards by the class name
resolves the problem.
So I just had to rewrite my class files like this:
class Test { // instead of module.exports = class Test {
constructor() {
console.log("Test.constructor");
}
}
module.exports = Test; // put the export to an extra line
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With