1

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

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.