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
19
votes
2 answers

jsdoc two dimensional array

I have an array of array of string and I can't figure out how to document that with JSDoc. /** @class */ function PostbackList() { /** @type {int} @default */ this.TypeID = 0; /** @type {PostbackList.Field[]} */ …
Serge Profafilecebook
  • 1,165
  • 1
  • 14
  • 32
19
votes
1 answer

documenting side-effects of javascript methods

I'm trying to improve the documentation of my javascript code, and am following the JSDoc guidelines https://jsdoc.app/. I can't find how to document an intentional side-effect. For example the following method: /** * @description * Paints the…
mastaBlasta
  • 5,700
  • 1
  • 24
  • 26
19
votes
4 answers

WebStorm: How to generate JSDoc documentation

I just started using WebStorm and JSDoc to document my JavaScript. Still I have not found a way to generate a HTML documentation using some kind of WebStorm built-in functionality. I searched the web and Stack Overflow, but only found a lot of…
Tobias
  • 193
  • 1
  • 1
  • 5
18
votes
2 answers

Convert Typescript with JsDoc

Can I convert TypeScript file to JavaScript file with JSDoc? For example, if I have this main.ts file: let x: string = "hello"; // This could be number or array of numbers let y: number | number[]; It will be converted to something like this…
18
votes
1 answer

JS Doc comment link method

In JavaScript comments, I want to mention a method present in some file. How can I link to that method in comment? Eg. Say my method is: function xyz() { } and say I am writing a comment like // See also {method-link to xyz} What should…
Chacha
  • 411
  • 1
  • 5
  • 12
18
votes
3 answers

JSDoc + Mongoose : how to document Mongoose models?

I have Mongoose schema and a model: var MyClientSchema = new mongoose.Schema({ fist_name: { type: String }, phone_number: { type: String } }); var MyClient = mongoose.model('MyClient', MyClientSchema); How should I…
Jan Grz
  • 1,373
  • 14
  • 18
18
votes
3 answers

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:…
gztomas
  • 3,030
  • 3
  • 27
  • 38
17
votes
5 answers

What is the JSDoc type for document.getElementById('myID') and a jQuery Element?

I'm trying to document my functions with JSDoc syntax. /** * * My Description * * @param {JQuery|???} input * @returns {JQuery} */ function foo(input){ return $('selector'); } The above function accepts a single argument which can be…
Drahcir
  • 11,772
  • 24
  • 86
  • 128
17
votes
1 answer

What's the correct casing to use for jsDoc comments?

I've recently started using jsdoc comments for documenting our javascript code, however I'm finding conflicting examples of the usage of the @param tag. See https://code.google.com/p/jsdoc-toolkit/wiki/TagParam (PascalCase) and…
magritte
  • 7,396
  • 10
  • 59
  • 79
17
votes
4 answers

How can I view the outline in eclipse when using the revealing module pattern?

I'm currently refactoring some Javascript code we have and amongst other things I've changed it to make use of the revealing module pattern. The code is looking much tidier and it works fine but I can't see the functions anymore in the outline view.…
Ben Thurley
  • 6,943
  • 4
  • 31
  • 54
16
votes
6 answers

How do I document useState hooks with JSDoc?

I'm trying to use JSDoc to document the destructured parts of my react state hooks for example: const [referenceState, setReferenceState] = useState(null); Here, referenceState is of type Object, and setReferenceState expects an Object. Based on…
theabhinavdas
  • 454
  • 4
  • 16
16
votes
2 answers

How to jsdoc annotate BackboneJS code?

Has anyone ever documented BackboneJS code with JSDoc? I'm having problems annotating Backbone constructs such as: User = Backbone.Model.extend({ defaults: { a: 1 }, initialize: function () { // ... }, doSomething:…
sean
  • 163
  • 1
  • 5
16
votes
2 answers

jsdoc @ character inside code block

I'm trying to write documentation for a Module function like this: /** * Usage: * * ``` * @NgModule({ * imports: [ * BrowserModule, * ..., * ThisModule.forRoot({ * name: 'Name', * …
Miquel
  • 8,339
  • 11
  • 59
  • 82
16
votes
1 answer

How to document deconstructed parameters with JsDoc

How do I document a function parameter that gets deconstructed in function arguments? /** * Function deconstructs argument and do stuff. * @param {} *** what should i do here? *** */ function someFunction({ key1, key2, key3 }) { // do…
Pulasthi Bandara
  • 526
  • 4
  • 16
16
votes
4 answers

How to use typescript jsdoc annotations for React PropTypes

When defining react components using typescript we can write something like: class SomeComponent extends React.Component { // ... } Is there a way do the equivalent using jsdoc annotations and have props…
lorefnon
  • 12,875
  • 6
  • 61
  • 93