35

if i write such code in webstorm

export class someOne {
  constructor(param) {
    this.test = param;
  }

  useTest(){
    return this.test;
  }
}


console.log(new someOne(123).useTest());

and mouseover on "this.test" i see the warning: "Element is not exported"

element is not exported wtf

what does it mean? if i change the .test to .test1 the warning disappears

ya_dimon
  • 3,483
  • 3
  • 31
  • 42
  • 1
    If it works, and changing the variable name makes the warning go away -- I suspect it's a conflict with webstorm's understanding of variable names. I came across this with MongoDB function names triggering deprecation warnings for non-Mongo features – Sterling Archer Apr 16 '16 at 23:31
  • Weird error. I've gotten this too when exporting classes in IntelliJ IDEA 2016.1.1. – E. Sundin Apr 19 '16 at 03:19
  • 1
    Same here. PhpStorm 2016.1 – wintercounter Apr 19 '16 at 07:40

2 Answers2

9

For me it worked to mark all "private" properties with a prefixed underscore. Obviously Webstorm/IntelliJ recognized the properties as something that should not be exported.

export class someOne {
  constructor(param) {
    this._test = param;
  }

  useTest(){
    return this._test;
  }
}


console.log(new someOne(123).useTest());
Fabian
  • 480
  • 6
  • 11
  • 1
    Douglas Crockford will not like this solution :). At the end the _test is just accessible, so it's not a private member at all. http://stackoverflow.com/questions/19359724/variable-naming-conventions-other-than-trailing-underscore – Niels Steenbeek Oct 26 '16 at 06:45
7

Webstorm just tries to prevent you adding unspecified attributes. You need to define getters/setters. This prevents adding and grabbing attributes as dirty hacks.

Update - added WeakMap to have variables really private.

let testWeakMap = new WeakMap();
export class someOne {
    constructor(param) {
        this.test = param;
    }

    useTest(){
        return this.test;
    }

    get test () {
        return testWeakMap.get(this);
    }

    set test (value) {
        testWeakMap.set(this, value);
    }
}
console.log(new someOne(123).useTest());
Niels Steenbeek
  • 4,692
  • 2
  • 41
  • 50
  • So what is proper way to make this warning go away? – redism Apr 25 '16 at 02:18
  • To simply suppress the warning, you can add //noinspection JSUnresolvedVariable before the property declaration. – Jbird May 10 '16 at 10:53
  • 13
    Or, in "Editor" > "Inspections" > "Javascript" > "General" > "Unresolved JavaScript variable" disable "Report undeclared properties as error" (PHPStorm 2016.1) – Jbird May 10 '16 at 11:00