Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I document a type in webstorm using just jsdoc?

When I write the following code, the annotator tells me that BrowserSelector is not defined in the second typedef:

/**
 * @typedef {{name: String, minVer: Number, maxVer: Number}} BrowserSelector
 */

/**
 * @typedef {{type:String, browser: BrowserSelector, attribute: Object}} Selector
 */

I believe it is not associating the type with the name. How can I do that?

I would prefer not to add actual code for it, just jsdoc comments.

like image 527
gztomas Avatar asked May 17 '13 13:05

gztomas


People also ask

How do you create a comment in JSDoc?

Create JSDoc commentsPosition the caret before the declaration of the method/function or field to document, type the opening block comment /** , and press Enter . WebStorm generates a JSDoc comment with a list of parameters ( @param ) and return values ( @returns ), where applicable.

What is JSDoc used for?

JSDoc is a markup language used to annotate JavaScript source code files. Using comments containing JSDoc, programmers can add documentation describing the application programming interface of the code they're creating.


2 Answers

I'm using this comment style for 'struct' like types:

/**
 * @name BrowserSelector
 * @property {String} name
 * @property {Number} minVer
 * @property {Number} maxVer
 */

/** @type {BrowserSelector|*} */
var mySelector = {}; // no warning because of '*' in @type :S
mySelector.name = 'foo'; // no warning :)
mySelector.id = 'bar'; // warning :)

like image 188
iolo Avatar answered Oct 08 '22 16:10

iolo


Multiple comments to describe properties is not necessary as of Webstorm 7 (perhaps earlier).

/**
 * @name BrowserSelector
 * @type {{
 *     name: String,
 *     minVer: Number,
 *     maxVer: Number
 * }}
 */
like image 20
Mike Cluck Avatar answered Oct 08 '22 16:10

Mike Cluck