简体   繁体   中英

jsdoc - default property value inside param object

For the following jsdoc @param object, how do I assign a default value to name ?

/** 
    @param inbound {{
        email: string,
        name: string,
        req: Req
    }}
*/

I have tried

/** 
    @param inbound {{
        email: string,
        name: [string=""],
        req: Req
    }}
*/

but that just turns it into an array [string, ""] .

I'm also preferring this @param style over @typedef as vscode shows me the properties of the object using @param , while it doesn't show it for @typedef

Optional parameters are documented in the document Types in the Closure Type System on the Closure Compiler wiki.

In short, the default value should be provided using JS.

/**
 * Some class, initialized with an optional value.
 * @param {!Object=} opt_value Some value (optional).
 * @constructor
 */
function MyClass(opt_value) {
  /**
   * Some value.
   * @private {!Object|undefined}
   */
  this.myValue_ = opt_value || 'foo';
}

However, your question specifically refers to a default property within a document. To my knowledged "deep defaulting" is not thing in vanilla JS, not in the method signature anyhow, so it's unlikely you will find a pure JSDocs way to accomplish this.

Just write a good description and implement in JS. You could create a very simple class with this default property being returned by a getter/setter.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM