javascriptvisual-studio-2017javascript-intellisensevisual-studio-community

Set ES5 class' property type using JSDoc


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?


Solution

  • 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.