5

I have class that has a property:

class MyClass {
    constructor() {
        this.property = null;
    }
}

The property can be null or an Array instance. I tried this:

/**
 * @property property {Array}
 */
class MyClass ...

This:

/**
 * @property MyClass.property {Array}
 */
class MyClass ...

And this:

class MyClass {
    /**
     * @property property {Array}
     */
    constructor() ...

And I'm still seeing this in intellisense:

<code>(property) MyClass.property: any</code>

So can anyone tell me how to do this correctly?

Tomáš Zato
  • 50,171
  • 52
  • 268
  • 778

1 Answers1

3

So far, the best approach was this:

class MyClass {
    constructor() {
        /** @type {MyClass2} **/
        this.property = null;
    }
}

It still is kind of buggy but most of the time it works.

Tomáš Zato
  • 50,171
  • 52
  • 268
  • 778
  • If the property is assigned from constructor parameter, then it's type can be inferred by Visual Studio (and Visual Studio Code). – Franklin Yu May 10 '18 at 16:15