Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get @borrows tag working in JSDoc

Tags:

jsdoc

I have been having a hard time getting the @borrows tag working in JSDoc. I have been trying to get the documentation from one function and us it as documentation for a second function. But I don't seem to be able to even get a simple example working!

/**
 * This is the description for funcA
 */
var funcA = function() {};

/**
 * @borrows funcA as funcB
 */
var funcB = function() {};

I was expecting this to output documentation for both functions with both exactly the same. However only funcA is only has a description.

like image 956
McShaman Avatar asked Apr 19 '15 07:04

McShaman


People also ask

What are JSDoc tags?

JSDoc is a markup language used to annotate JavaScript source code files. Using comments containing JSDoc, programmers can add documentation describing the application programming interface of the code they're creating.

Does JSDoc work with TypeScript?

You can use most JSDoc type syntax and any TypeScript syntax, from the most basic like string to the most advanced, like conditional types.

How do you write comments in JSDoc?

Create JSDoc commentsPosition the caret before the declaration of the method/function or field to document, type the opening block comment /** , and press Enter . WebStorm generates a JSDoc comment with a list of parameters ( @param ) and return values ( @returns ), where applicable.

Is JSDoc useful?

JSDoc makes coding in JavaScript easier, helping us to code quickly while avoiding obvious errors, just by adding some lines of optional comments in our code.


1 Answers

The @borrows tag doesn't seem to work directly on a symbol, but only indirectly. For example I had:

/** does amazing things */
function origFunc = function() {};

/**
 * @borrows origFunc as exportedFunc
 */
exports.exportedFunc = origFunc;

but I, like you, got nothing useful in the generated doc.

That is because, it seems, that the @borrows tag operates on a container. (If you'll notice in the examples the @borrows tag is on the "util" module/namespace, not the renamed symbol.)

So this worked for me:

/** does amazing things */
function origFunc = function() {};

/**
 * @borrows origFunc as exportedFunc
 */
exports = {
  exportedFunc: origFunc,
}

Seems like a bug in @borrows though. (Or at least a bug in the documentation.)

like image 152
P.T. Avatar answered Oct 16 '22 06:10

P.T.