For more examples visit compiler annotation
/**
* @param {type} a
* @return {type}
*/
function foo(a) {
return a;
}
var b = /** @type {type} */ (a);
foo(/** @type {type} */ (a));
/**
* @type {type}
*/
Foo.prototype.a;
/**
* @type {*} Whatever
*/
Foo.prototype.a;
/**
* @type {string|number|undefined} String or number or undefined
*/
Foo.prototype.b;
/**
* @type {?string} String or null
*/
Foo.prototype.c;
/**
* @param {!string} a Required parameter
* @param {string=} opt_b Optional parameter
*/
Foo.prototype.bar = function(a, opt_b) {
}
/** @type {number} */
/** @type {string} */
/** @type {boolean} */
/** @type {undefined} */
/** @type {null} */
/**
* @const
* @type {number}
*/
Foo.A = 1;
/**
* @const
* @type {string}
*/
Foo.B = 'text';
/**
* @param {Array}
*/
/**
* @param {Array.<*>} Array of unknown/whatever items
* @param {Array.<string>} Items in array are strings
* @param {Array.<Object>} Items in array are Objects
*/
/**
* @param {Array.<Array.<string>>} Items in array are Arrays of strings
*/
/**
* @param {Object}
*/
/**
* @param {Object.<number, string>} Object with number keys and string values
*/
/**
* @param {Function}
*/
/**
* @param {function(): boolean} Param is a function which return boolean
* @param {function(number): boolean} Function with number as parameter and return boolean
*/
/** @type {Element} */
/** @type {Document} */
/** @type {DocumentFragment} */
/** @type {Node} */
/** @type {NodeList} */
/** @type {Window} */
/** @type {HTMLAnchorElement} */
/** @type {HTMLDocument} */
/** @type {HTMLElement} */
/** @type {HTMLFormElement} */
/** @type {HTMLImageElement} */
/**
* @typedef {{
* id: number,
* direction: string
* }}
*/
Foo.NAVIGATE_INFO;
/**
* @type {Foo.NAVIGATE_INFO}
*/
Foo.prototype.info;
/**
* Function returning "typedef". Property "style" can be string or null.
*
* @return {{link: string, href: string, style: (string|null)}}
*/
Foo.prototype.getLink = function() {
// ...
return {
link: 'Link',
href: 'http://...',
style: null
};
}
/**
* @enum {string}
*/
Foo.Api = {
GET: '/get',
PUT: '/put'
}
/**
* @enum {number}
*/
Foo.Direction= {
UP: 1,
DOWN: 2
}
/**
* @param {...string} var_args
*/
Foo.prototype.insertAll = function(var_args) {
// arguments, arguments.length
};
/**
* @interface
*/
Foo = function() {};
/**
* @param {number} a
*/
Foo.prototype.bar = function(a) {};
/**
* @constructor
* @implements {Foo}
*/
app.Some = () {
};
/**
* @param {number} a
*/
app.Some.prototype.bar = function(a) {
};
/**
* @constructor
* @extends {app.Some}
*/
app.Other = () {
goog.base(this);
};