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

JSDoc with AngularJS

Currently within my Project we are using JSDoc, we have recently started to implement Angular and I want to continue using JSDoc to ensure that all the documentation is within the same place. I have taken a look at people mainly just saying to use…
Nick White
  • 1,602
  • 4
  • 20
  • 35
31
votes
1 answer

JSDoc equivalent to Typescript's `as const`?

I'm in an old project that is too huge to easily convert to Typescript, so I've been using JSDoc instead. The Typescript feature that I can't figure out how to replicate in JSDoc is using as const to fully type the property names and values of a…
Adam Coster
  • 1,162
  • 1
  • 9
  • 16
31
votes
3 answers

Why Doesn't jQuery use JSDoc?

Or do they and it's just not in the source? I'd really like to get something that will stop js-doc-toolkit from freaking out each time it parses jQuery. It also means I can't properly document any code using jQuery as a dependency without at least…
hlfcoding
  • 2,532
  • 1
  • 21
  • 25
31
votes
3 answers

JSDocs: Documenting Node.js express routes

I am struggling documenting router.get calls with JSDocs. I am unable to get the documentation to display correctly on the page if I try to append it to my router call itself. /** * Health check * @memberof health */ router.get('/happy',…
Soatl
  • 10,224
  • 28
  • 95
  • 153
31
votes
5 answers

How to force newlines in Google Apps jsdoc descriptions

I can't figure out how in a Google Apps Script to display this correctly. I need it to display new lines in the jsdoc output(e.g. when the function tooltip window comes up in a Spreadheet functions.) I have tried html like however it is just…
masshuu
  • 471
  • 1
  • 4
  • 6
30
votes
2 answers

How to document callbacks using JSDoc?

Given a Javascript function that takes callback functions as parameters: var myFunction = function(onSuccess, onFailure) {...} How do I document onSuccess's return type and arguments?
Gili
  • 86,244
  • 97
  • 390
  • 689
29
votes
1 answer

Nested Methods in sidebar of JSDoc

Thanks to the answer found here: https://stackoverflow.com/a/19336366/592495 My JavaScript documentation is well-organized and well-formatted. Each namespace is a "parent" of methods contained within. However, navigation is not quite as granular as…
Greg Pettit
  • 10,749
  • 5
  • 53
  • 72
28
votes
2 answers

How to resolve 'Assertions require every name in the call target to be declared with an explicit type annotation.ts(2775)'?

I have the JavaScript code below, and I'm using the TypeScript Compiler (TSC) to provide type-checking as per the Typescript Docs JSDoc Reference. const assert = require('assert'); const mocha = require('mocha'); mocha.describe('Array', () => { …
derekbaker783
  • 8,109
  • 4
  • 36
  • 50
28
votes
2 answers

JSDoc @param together with @deprecated

I have a JavaScript function getting some parameters including object types. However, one property of a parameter, which is an object, will be used as deprecated. I would like to indicate this situation in the documentation, however I don't know how…
moztemur
  • 941
  • 1
  • 9
  • 22
28
votes
5 answers

How to document a Require.js (AMD) Modul with jsdoc 3 or jsdoc?

I have 2 types of Modules: Require.js Main File: require.config({ baseUrl: "/another/path", paths: { "some": "some/v1.0" }, waitSeconds: 15, locale: "fr-fr" }); require( ["some/module",…
3logy
  • 2,634
  • 8
  • 46
  • 99
27
votes
5 answers

Default "Home" text and content for JSDoc

After running a basic JSDoc compile/render from Node.js: jsdoc file1.js file2.js I get a well-formatted document using the default template inside a directory "out". Almost all is as expected! But when opening the document, it always says "Home" on…
Greg Pettit
  • 10,749
  • 5
  • 53
  • 72
26
votes
2 answers

How to cast TypeScript type in javascript using JSDoc

When using TypeScript to check JavaScript code, how do you cast to a different type than is inferred? Typescript has the and as Type syntax but these aren't valid in JavaScript. /** * @param {{id: string, value: number}} details - object…
Chic
  • 9,836
  • 4
  • 33
  • 62
26
votes
3 answers

jsdoc @typedef - how to declare function properly?

Here is my jsdoc declaration. How should I adjust it, so that MyNewType.logFirst property actually references logFirst function, which I've annotated below? // my-new-type.js /** * MyNewType definition * @typedef {Object} MyNewType * @property…
Pavel Polyakov
  • 866
  • 1
  • 8
  • 13
26
votes
2 answers

JsDoc: How do I document that an object can have arbritrary (unknown) properties but with a particular type?

This is a similar to question 30360391. I want to express that the parameter of a function is a plain JS object that can have arbitrary properties (with unknown) names but all properties are objects themselves with fixed properties. An example: The…
user2690527
  • 1,729
  • 1
  • 22
  • 38
26
votes
1 answer

Do primitive type names need to be uppercase or lowercase?

/** * @param {String} foo * @param {Number} bar */ or /** * @param {string} foo * @param {number} bar */ JSDoc @type documentation is not being explicit about it. I always uppercase String and Number because it is my understanding that I…
Gajus
  • 69,002
  • 70
  • 275
  • 438