JSDoc doesn't generete doc for ES6 functions like export const myFunction = ( ) => ........
Input code
When you declare an arrow function with an export like:
/**
* Description.
* @param {object} userInfo description
*/
export const setUserInfo = userInfo => ({ userInfo });
The generated documentation takes it like a constant while removing the export the documentation is generated fine.
JSDoc configuration
Default configuration
JSDoc debug output
No output
Expected behavior
Current behavior
Your environment
| Software | Version |
|---|---|
| JSDoc | 3.5.5 |
| Node.js | 8.9.4 |
| npm | 5.7.1 |
| Operating system | Windows 10 |
I encounter the same kind of issue when you declare a class in the export section. ie:
export default class Embedded {
...
}
The best solution to address this, is to declare and export separately :
/**
* Description.
* @param {object} userInfo description
*/
const setUserInfo = userInfo => ({ userInfo });
export default setUserInfo;
and I got a documentation's result close to what you wanted:

I was with the same problem and I didn't find a solution. I have a utils file with multiple exported functions and the 'export default' solution didn't be good in my case. I resolved that putting @method above the @params. Like this:
/**
* @method
* @param {String} str
* @return {String}
*/
I don't if it's the best solution but I hope to help people with the same issue.
There is problem with the (arrow or regular) function expression exported (without tag @function, @func or @method).
Input code
/**
* Foo
*/
export const foo = function () { };
/**
* Bar
*/
export const bar = () => { };
/**
* Baz
* @function
*/
export const baz = function () { };
/**
* Quz
*/
export function quz() { }
/**
* Quux
*/
const quux = function () { };
JSDoc
Members
(static, constant) bar Bar
(static, constant) foo Foo
Methods
(static) baz() Baz
(static) quz() Quz
(inner) quux() Quux
What is the correct way to document ES6 code with JSDoc as of 2020?
You need to add @module tag at the start of the document like so
/** @module user */ assuming
useris a module name
More info on the docs
document = JS file?
Yes the JS file
Facing same issue with JSDoc 3.6.4.
Adding /** @module moduleName */ at the top of the file doesn't solve the issue. Only viable solution so far is using @function, which is a bit annoying.
I wonder if we are doing something wrong or if this is an actual bug.
/** * Baz * @function */ export const baz = function () { };
This works!! Awesome
Is adding the @function decorator still the best solution for this? Thoughts, all?
Is adding the
@functiondecorator still the best solution for this? Thoughts, all?
This is what I use, in fact, I setup a snippet in VSCODE to auto comment my functions to save me the time of having to remember to add it. Now it's just part of my workflow.
Do you guys know why this problem happens?
The same problem happens when exporting simple constants like numbers or strings with the @default decorator.
I use this pattern alot: I have a constants.js file which can export lots of constant variables.
/**
* a maximum value
* @constant
* @type {Number}
* @default
*/
export const MAX_VALUE = 20;
The @default decorator should add the constant value to the documentation, but it doesn't. If I remove the export, it works.
There is some issue with the ES6 exports here. And in this case, there seems to be no decorator to use as a workaround.
Hello, Kinda late, but I figured out a workaround (I guess), but it makes the code looks messy. I named the parameter object, added default values, and then I wrote the description of each parameter inside the deconstructed parameter like this:
export default => ({
param = {
/**
write what you like here
@see {@link whatever}
*/
paramName,
/**
another description
*/
anotherParamName
})
{
// your code
}
Just run into this as well while using
export default class Foo {
// stuff
}
while this worked fine:
class Foo {
// stuff
}
export default Foo;
Has there been any update on this? I'm trying to write a codebase in valid, standard ES2015 (standardized in 2015 I believe) and have typing support, but there doesn't seem to be any tooling that supports it!
Exporting default doesn't work, because one then can't import specific symbols using the import syntax.
Weirdly it works only if I add @methodOf {modulename} AND @function to each exported function:
/** @module tasks/methods */
/**
* Creates a new task document
* @methodOf {tasks/methods}
* @function
* @param text {string}
* @return {string} inserted document _id
*/
export const insertTask = function ({ text }) {
// ...
}
otherwise it won't get listed with params and return type etc.