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

VSCode indent in Swagger JSDoc

I'm using swagger-jsdoc with Express. Using this lib to describe an api end-point I use following lines in JSDock block in YAML: /** * @swagger * /users: * post: * summary: Register a user * tags: [Users] * description:…
Darkzarich
  • 470
  • 6
  • 18
14
votes
2 answers

VSCode: How to document promise that resolves with complex object?

I have a function f that returns a Promise. The returned Promise either resolve({name: String, data: Object}) or reject(Error). I've tried the following syntax(as mentioned in an issue in JSDoc) in VSCode, but it doesn't work: /** * @promise…
lz96
  • 2,816
  • 2
  • 28
  • 46
14
votes
1 answer

JSDoc: declare @type for variable in "for...of" loop

Can I declare type for variable one using JSDoc @type annotation? /** @type some.type */ for (let one of many) { ... } Something like PHPDoc annotation: /** @var \Some\Type $one */ foreach ($many as $one) { }
Alex Gusev
  • 1,526
  • 3
  • 16
  • 35
14
votes
1 answer

JSDoc - How to document object with generic key names?

I need to document an ES6 class with JSDoc that takes in an object that has properties that has the key names as names of people so the key names can be pretty much any string, nothing predefined. So the structure of the object should be like the…
HaSte
  • 183
  • 1
  • 1
  • 7
14
votes
2 answers

How to describe destructured object arguments in JSDoc

If I have a JavaScript function taking an object as a parameter, I can describe expected properties of the object with JSDoc like this: /** * @param bar * @param bar.baz {number} * @param bar.qux {number} */ function foo(bar) { return…
Henrik
  • 4,254
  • 15
  • 28
14
votes
1 answer

Intellisense not working with imports in Visual Studio Code

When using javascript (es2015) imports the Intellisense seems to be broken. When I am working in the same file, VSC autosuggests the methods from the object with the correct JSDoc information. However, when importing the Class in another file, the…
koningdavid
  • 7,903
  • 7
  • 35
  • 46
14
votes
1 answer

How to document JavaScript configuration objects in Visual Studio Intellisense

I have been using Visual Studio's JavaScript Intellisense functionality for a while now and have mostly been happy with how well it provides suggestions for standard APIs, but I have found that I cannot get Visual Studio to understand configuration…
14
votes
2 answers

Is it possible to tell jsdoc to look in a file separate from the source code for documentation of that code?

I would like to keep inline comments as short as possible, since my experience is that comments of more than 3 or 4 lines tend to be glossed over, creating a lot of unnecessary "read the manual lines". I'm required by legacy to adhere to a…
user2999782
  • 153
  • 1
  • 5
14
votes
3 answers

How to document return in JavaScript

I'm writing my own library for the project at work for a browser application and I am having the same old problem deciding how to comment the code. I'm trying to follow the JsDoc syntax, but will probably continue the Google Closure Compiler way. I…
Azder
  • 4,698
  • 7
  • 37
  • 57
13
votes
2 answers

JSDoc + IDE vs. TypeScript

With a properly maintained JSDoc, almost any modern IDE can identify a type mismatch (of assignments, functions' signatures/arguments) and many other issues that a non-strongly-typed language introduces. Besides that, modern JS comes with a…
Mike
  • 14,010
  • 29
  • 101
  • 161
13
votes
6 answers

How to pass a generic type argument with JSDoc?

Before giving up I wanted to give it a shot here. I have a definition file with typings like the following: /** * My json decode function, in reality very different * implementation (class like) but it works as an example */ function…
Steven Guerrero
  • 876
  • 8
  • 17
13
votes
2 answers

JSDoc and JavaScript property getters and setters

I was hoping that my code, something like below, could generate documents describing each property of the object literal with JSDoc(v2.4.0), but it did not work. Does anyone know how to work with JSDoc to generate documents from code that uses…
enobufs
  • 860
  • 1
  • 7
  • 12
13
votes
4 answers

Why doesn't Closure Compiler recognize type declarations inside a self-executing anonymous function?

I'm getting a lot of "Unknown type" warnings when running a fairly large library through Closure Compiler, and they seem to occur when my types are declared in self-executing anonymous functions. There's nothing exotic about this, but if I strip the…
jpdaigle
  • 1,265
  • 10
  • 12
13
votes
3 answers

jsdoc and vscode: Documenting a function passed as an argument to another function

I'm trying to document the input parameters to a function in javascript, but I can't work out how to do it in jsdoc. I've looked at the jsdoc documentation which suggests that using the @callback comment is what's required, but Visual Studio Code…
a-h
  • 4,244
  • 2
  • 23
  • 29
13
votes
4 answers

TypeScript strips down comments and spoils JSDoc documentation

The objective is to get JSDoc documentation from TypeScript code. The quality of documentation from TypeDoc (TypeScript documentation solution) isn't acceptable because the documentation is targeted at JS users and shouldn't be flooded with the…
Estus Flask
  • 206,104
  • 70
  • 425
  • 565