Is it possible to enable JS object intellisense in prototype accessors in Visual Studio Code?

Viewed 1613

When creating a JS object and defining some accessors, I found that I couldn't get the intellisense after this.

Example code :

function Obj(foo) {
    this.foo = foo;
}

Obj.prototype = {
    get bar() {
        return this.// No intellisense here
    },
    set bar(val) {
        this.foo = val
    }
};

But creating a method with Obj.prototype.test = function () {...} will get me the intellisense.

Is there any way to replicate the same lexical analysis for this case with the user settings, or is it an actual flaw / bug ?

Edit: here is an image of what VSCode shows : VSCode intellisense

As you can see, it only shows previously used words, and nothing else.

Edit (03/04/2019): After trying again today, with v1.32.2, I noticed VSCode is able to suggest the bar property, but still not foo. So something was improved, but my issue not solved.

2 Answers

Use jsdoc

function Obj(foo) {
  this.foo = foo;
}
  /** @typedef {{foo:any,bar:any}} ObjThis*/

Obj.prototype = {
  /** @this {ObjThis}*/
  get bar() {
      return this.bar// No intellisense here
  },
  /** @this {ObjThis}*/
  set bar(val) {
      this.foo = val
  }
};
Related