1

I have a simple class User and I am using ES5:

/**
 * @property {number} id
 * @property {string} username
 * @property {string} password
 * @property {string} email
 */
class User {
  
  constructor(obj) {
    ...
  }
}

However I cannot get VSCode's intellisense to hint any of the instance properties if I type say:

let a = new User();
a.|      <-- Here intellisense should hint me id, username, etc...

Intellisense will only hint properties if I explicitly declare them in the constructor like so:

constructor(obj) {
    this.id = 1;
    this.username = '';
}

How can I write the JSDoc in the correct form?

Constantin
  • 848
  • 8
  • 23
  • Does this answer your question? [How to use JSDoc to document an ES6 class property](https://stackoverflow.com/questions/51467835/how-to-use-jsdoc-to-document-an-es6-class-property) - you may also want to move your jsdoc to markup the constructor instead of the class. – chazsolo Oct 21 '21 at 19:18
  • I have also tried that. It seems that properties are not hinting unless I assign the variables in the constructor. – Constantin Oct 21 '21 at 19:26

1 Answers1

4

Try this:

class User {
  /** @type {number} */
  id
  /** @type {string} */
  username
  /** @type {string} */
  password
  /** @type {string} */
  email

  constructor(obj) {
    // ...
  }
}

Screenshot

lepsch
  • 8,927
  • 5
  • 24
  • 44
YOLO
  • 41
  • 6