I need to document a simple object and I'm failing to find a documentation or tutorial how to document @param
and @returns
for the inner methods. If I put them above the respective method ( xyz
), they are ignored, if I put them above the object, @param
is not assigned (or I have no idea how to assign it here).
Let's say it's a simple object, like this:
export const foo = {
abc: 'A string',
xyz: (x) => {
return x + '!'
}
}
I expected something like this should work:
/**
* @module FooModule
*/
/**
* @type {object}
*/
export const foo = {
/**
* @property {string} abc - some property
*/
abc: 'A string',
/**
* @property {function} xyz - some method
* @param {string} x - source string
* @returns {string} - exclamation mark added
*/
xyz: (x) => {
return x + '!'
}
}
But it doesn't work, obviously. I've found a similar question here but the solution is wrong, it doesn't work at all. How should this be done correctly, so that I get a module FooModule
, a global constant foo
with foo.abc
property and foo.xyz
method (incl. @param
and @returns
) in the output JSDoc?
Can it be done? If yes, can it be done without @typedef
ing all functions like this?
It seems the latest answer to other question found the problem. It's not in the JSDoc syntax, but in the javascript itself. It seems JSDoc's @module
can't be used with the export
directive. If @module
is removed, the documentation works as expected. If @module
is used, the export
must be replaced by
module.exports = foo
at the end. Then the JSDoc build works fine.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.