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
46
votes
3 answers

How do I refer to another typescript type in comments/JSDoc?

I'm familiar with Javadoc. In Javadoc, you can place a link that refers to the Javadoc placed on another type like so: /** * some java thingy. see this other java thingy too {@link OtherThingy} */ public class Thingy { /*...*/ } /** * some other…
Rico Kahler
  • 17,616
  • 11
  • 59
  • 85
46
votes
6 answers

JSDoc typedef in a separate file

Can I define all custom types in a separate file (e.g. types.jsdoc), so that they can be reused throughout the application? What's the right way to do it? /** * 2d coordinates. * @typedef {Object} Coordinates * @property {Number} x - Coordinate…
Edward Ruchevits
  • 6,411
  • 12
  • 51
  • 86
45
votes
3 answers

How to document the properties of the object in the JSDoc 3 tag: @this

The @param tag allow the documentation of properties, e.g. /** * @param {Object} userInfo Information about the user. * @param {String} userInfo.name The name of the user. * @param {String} userInfo.email The email of the user. */ How…
Matt
  • 4,261
  • 4
  • 39
  • 60
43
votes
1 answer

TypeScript jsdoc for interface properties

I have a TypeScript interface with a single-character property name (a design constraint). I would like to use JSDoc to document this interface to help with auto-complete in vscode. Here's the current interface: export interface ISource { b:…
Mike Crowe
  • 2,203
  • 3
  • 22
  • 37
42
votes
3 answers

How to JsDoc a "mixed" type?

Simple question, how do I document that "Mixed-type"? I know I could just list all possible types like {null|undefined|String|Number|Object} and end up finding myself missing one and making it overly complex. I tried using the Mixed keyword, but it…
Tower
  • 98,741
  • 129
  • 357
  • 507
41
votes
6 answers

How to do documentation in ReactJS?

I have a requirement to create the doc file of each of the component we define in our reactjs application. I am looking for the npm that we can use for creating the document of any extension, so that it may extract the code, comment everything from…
Gorakh Nath
  • 9,140
  • 15
  • 46
  • 68
40
votes
2 answers

How to document ECMA6 classes with JSDoc?

Background I have a project in Nodejs using ECMA6 classes and I am using JSDoc to comment my code, as to make it more accessible to other developers. However, my comments are not well accepted by the tool, and my documentation is a train wreck.…
Flame_Phoenix
  • 16,489
  • 37
  • 131
  • 266
39
votes
3 answers

How to use JSDoc to document an ES6 class property

I'm using the documentation package, but cannot figure out how to get it to document class properties (that aren't defined via getters and setters). As the following just generates class documentation for SomeClass, but omits the someProperty…
balupton
  • 47,113
  • 32
  • 131
  • 182
39
votes
1 answer

Insert relative link in reStructuredText

I am documenting a library that has a Python component and a JavaScript component. The overall user documentation, and the Python API documentation are in reStructuredText, processed with Sphinx. The JavaScript API is in jsdoc and is processed with…
Dan Menes
  • 6,667
  • 1
  • 33
  • 35
37
votes
5 answers

jQuery compatible JavaScript documentation generator

I need to choose a documentation generator (similar to jdoc in java or rdoc in ruby) for my javascript project that (built with jquery, underscore and backbone) Candidates: jsdoc toolkit pdoc natural docs docco YUI doc doctool…
clyfe
  • 23,695
  • 8
  • 85
  • 109
35
votes
5 answers

Document collection (array of type) return value and parameter in JSDoc

How to document Array return value (and parameters) in JSDoc when array elements can be either of the following: A type (e.g. String, Array). An object literal.
Jonathan Chan
  • 2,355
  • 3
  • 25
  • 38
35
votes
2 answers

How to document anonymous functions (closure) with jsdoc-toolkit

I am trying to document my code using JSDoc-toolkit. My code starts by being wrapped with a self-executing anonymous function. How in the world do I document this? I've spent nearly all day on this. JS Docs will not recognize anything inside of the…
Jesse Atkinson
  • 10,586
  • 13
  • 42
  • 45
35
votes
2 answers

How to get VS Code to understand JSDOC's @typedef across multiple files

I want to specify a type in one file, and be able to reuse it in another one. I tried modules but it didn't work in VS Code. Is there any other solution? Just wanna have all types for my project to be reusable so I can reference them in different…
zavr
  • 2,049
  • 2
  • 18
  • 28
35
votes
1 answer

How can I get JSDoc to mark my param as a jQuery object?

I'm attempting to thoroughly comment my JavaScript and I'm using JSDoc. I have a function that consumes a jQuery object and I'd like to mark the parameter as such. Currently, I have this: /** * Initializes a login object. * @param formEl {JQuery}…
Nick G.
  • 1,145
  • 2
  • 10
  • 19
33
votes
6 answers

How can I generate JavaScript API documentation for GitHub Pages

There are a lot of great options for generating API documentation for other languages, but I have yet to find a solution for my JavaScript API that I want to host on GitHub Pages. It seem that I can use JSDoc3 but I would need to create a custom…