const objectname = {
property: 0,
set (value) {
this.property = value;
}
}
How would you document these example lines with JSDoc comments?
This is what I already tried but it doesn’t show objectName.set
as a method and doesn’t show its parameters.
/**
* Represents an object with a property and a set method.
* @typedef {object} ObjectName
* @property {number} property - The numeric property of the object.
* @property {Function} set - Sets the property value to the specified value.
* @param {number} value - The value to set the property to.
* @returns {void}
*/
/**
* An instance of ObjectName.
* @type {ObjectName}
*/
const objectName = {
property: 0,
/**
* Sets the property value to the specified value.
* @param {number} value - The value to set the property to.
* @returns {void}
*/
set(value) {
this.property = value;
}
};
2
Answers
I’m not a JSDoc expert, and maybe I’m being too simplistic, but this seems to work:
When I use that in VS Code, I get the type and description of things (including the parameter type on
set
) in popups and such.The @param and @returns tags belongs inside the JSDoc comment for the set method, not in the @typedef comment for ObjectName.
VSCode works if I remove
Here is a corrected version
VSCode: