Jbobo Lee
Jbobo Lee

Reputation: 43

How do I specify @param @return for object type in Google Closure Compiler?

In javascript code, I have this function

/*
 * @param 
 * @return
 */
foo = function (oObjFoo) {
      // do something
      return oObjBar;
}

oObjFoo is type : {"a":number, "b":text, "c": bool }

oObjBar is type : {"c":number, "d":text }

How do I specify the @param, @return to do much stricter type check with the google closure compiler?

Upvotes: 0

Views: 137

Answers (2)

Tyler
Tyler

Reputation: 22116

/**
 * @param {{a:number, b:string, c: boolean }} oObjFoo
 * @return {{c:number, d:string}}
 */
var foo = function (oObjFoo) {
  // do something
  return oObjBar;
}

Note that the comment must start with a double asterisk for the compiler to count it as a JsDoc comment.

Upvotes: 2

mat
mat

Reputation: 1378

Take a look at JSDoc:

http://usejsdoc.org/tags-param.html

/**
 * @param {Object} oAttributes
 * @param {namespace.extension=} oAttributes.parent DOC-Description
 * @param {jQuery=} oAttributes.$element Optional jQuery-Element
 */

Upvotes: 0

Related Questions