Questions tagged [jsdoc]

JSDoc is a markup language for adding inline API documentation to JavaScript source code. This is distinct from the various tools that parse and manipulate code that follows the JSDoc syntax.

The JSDoc markup language is similar to the Javadoc syntax, used for documenting Java code, but is specialized to work with JavaScript's more dynamic syntax and therefore unique, as it is not completely compatible with Javadoc. However, like Javadoc, JSDoc allows the programmer to create doclets and tags which can then be translated into published output, like HTML or RTF.

Example:

/**
    Represents a book.
    @constructor
    @param {string} title - The title of the book.
    @param {string} author - The author of the book.
 */
function Book(title, author) {
}

The following annotations are commonly used in modern JSDoc, but the full list varies between implementations:

  • @param Documents a method parameter; a datatype indicator can be added between curly braces
  • @return Documents a return value
  • @constructor Marks a function as a constructor
  • @deprecated Marks a method as deprecated
  • @private Signifies that a method is private
  • @requires Describe a required resource.
  • @this Specifies the type of the object to which the keyword "this" refers within a function.
  • @throws Documents an exception thrown by a method
  • @exception Synonym for @throws
  • @author Developer's name
  • @version Provides the version number of a library
1697 questions
24
votes
1 answer

How to document an array of objects in JSDOC

I have a function with an array of objects as parameter and would like to describe the parameter (including the properties of the objects in the array) using JSDOC like in this example: /** * @param {Array.} filter - array of filter…
doberkofler
  • 9,511
  • 18
  • 74
  • 126
24
votes
2 answers

What's the correct way to document a jQuery parameter type with JSDoc?

I'm trying to document my program with the JSDoc syntax for myself and the people that will have to look at my code. I'm also trying to improve my skills. For a parameter of the jQuery type, I'm a little puzzled. I know that's an object, but it's…
23
votes
5 answers

JSDoc - how to document prototype methods

I've been trying to document the following code using JSDoc: /** * @module person */ /** * A human being. * @class * @param {string} name */ function Person(name){ this.name = name } Person.prototype = new function(){ var…
21
votes
4 answers

How to document destructured variable with jsdoc

I have something like this: let { total } = settings; How do I document the total variable? I tried something like this: /** * @type {Object} * @property {String} total.test */ let { total } = settings; but it doesn't seem to be the right…
Tommy Gaudreau
  • 250
  • 2
  • 6
21
votes
4 answers

Refer to type in different file in JSDoc without importing

I'm writing JavaScript (ES6) code in Visual Studio Code and enabled VSCode's type checking as explained in the VSCode docs. When referring to a type that is defined in another file (Track in the example below), I get an error like [js] Cannot find…
ralfstx
  • 3,893
  • 2
  • 25
  • 41
21
votes
1 answer

How to annotate anonymous object with optional property in JSDoc

I have a JavaScript class that takes one argument of type Object with defined set of properties and the Closure Compiler is happy when I annotate it like: @constructor @param {{ subview:BaseView, el:(jQuery|Element), title:String }} options var…
Pawel Dobierski
  • 407
  • 1
  • 4
  • 8
20
votes
1 answer

dynamic keys in jsdoc typedef

Is it possible to have dynamic keys (prop names) in a jsdoc typedef? I'm imagining this would look something like the example below (which does not work). @typedef {Object} Foo @property {string} bar @property {*} * Passing properties not listed in…
J'e
  • 3,014
  • 4
  • 31
  • 55
20
votes
2 answers

JSDoc Tag Support for React HOC (Higher-Order Component)

What is the proper way to document a React Higher-Order Component using JSDoc? There aren't, of course, any React-specific tags built-in - so what would be the proper approach?
20
votes
4 answers

jsdoc: multiline description @property

I am documenting my code using jsdoc, so far so good, I have a comment like below ... * @property {string} mode - mode of display 'video' - display video or 'audio' - play only the audio. * @property... and it comes in html document like | ... …
mido
  • 24,198
  • 15
  • 92
  • 117
20
votes
2 answers

How can I omit the source links in JsDoc?

What's the easiest way to cause JsDoc to leave out the source links? Do I have to define my own template?
jwl
  • 10,268
  • 14
  • 53
  • 91
20
votes
2 answers

How to jsdoc indicate that @param is the MouseEvent?

How to jsdoc indicate that @param is the MouseEvent? the HTMLElement DIV? /** * @param {MouseEvent} e */ window.clickToButton = function(e) { console.dir(e); } /** * @param {HTMLElement} d */ window.clickToDiv = function(d) { …
Danilovonline
  • 481
  • 1
  • 3
  • 7
19
votes
4 answers

linux shell append variable parameters to command

I am trying to get a bash script that generates JSDoc for given parameters like this ./jsdoc.sh file.js another.js maybe-a-third.js I am getting stuck on how to pass an unknown quantity of parameters to the next shell command. (also, don't know how…
Billy Moon
  • 57,113
  • 24
  • 136
  • 237
19
votes
2 answers

JSDoc Comment Folding In VSCode

Is there a way to fold JSDoc-style comment blocks in VSCode v1.25 for JavaScript files? I get normal code collapse offered, but comment blocks seem excluded. Is there a keyboard shortcut that would collapse code even without the GUI handlebars…
alphadogg
  • 12,762
  • 9
  • 54
  • 88
19
votes
4 answers

How do I use JSDoc on Windows?

Forgive me if this is a daft question but I'm utterly baffled as to how I can use JSDoc on Windows. I'm aware of JSDoc-Toolkit but it's a bit out of date and the google code repository recommends to use JSDoc 3 instead. I have downloaded JSDoc from…
19
votes
1 answer

jsdoc proper way to document socket.on('event', function() {}) and routes handler

How to document API using jsdoc which has following form (single file) // api.js exports.addSocketEvents = function(socket) { /** * This will do that and ... * @param {Object} data Some data * @param {string} data.bla Something about…
Srle
  • 10,366
  • 8
  • 34
  • 63