'JSDOC: Is it possible to link to a module property?
I'd like know if it's possible to link from one module to another module`s property/method.
What I've tried so far but wasn't working:
/**
* {@link module:modules/modulName#id}
*/
My modules follow this pattern:
/**
* @module modules/modulName
*/
define(function() {
'use strict';
/**
* @alias module:modules/modulName
*/
var module = {
/** Initialisation */
init: function() {}
};
return module;
});
Is there a way to achieve what I want?
Solution 1:[1]
Ok so from what I managed to do on my own
/**
* @module namespace/moduleName
*/
/**
* @name module:namespace/moduleName#propName
* @type {Object}
*/
const propName= {}
Then in another file you can reference with:
/*
* @see module:namespace/moduleName#propName
*/
You can use @link or even @type if you have @typedef with that name.
Tested this with PHPStorm and it works as it should. No idea for auto generated API's with JSDOC.
Solution 2:[2]
For this, I declare the property I want to reference as @memberof its own module (yes, it is in the same module where the @link tag is).
Then, I just do: {@link module:moduleName.property|textOfTheLink}
Example:
i18n.js module
/**
* @category Lib
* @subcategory i18n
* @module i18n
*/
/**
* Memoized translate method.
*
* @memberof module:i18n <----- THIS
* @type {MemoizedFunction}
* @function translate
* @param {i18n.Scope} scope - The translation scope.
* @param {i18n.TranslateOptions} [options] - Translate options.
* @version 1.0.0
* @since 1.0.0
* @example
* return <Text>{translate("home.title")}</Text>;
*/
export const translate = memoize(
(scope, options = undefined) => i18n.t(scope, options),
(scope, options = undefined) =>
options ? scope + JSON.stringify(options) : scope
);
/**
* Shorthand version of the {@link module:i18n.translate|translate} method. <----- COMBINED WITH THIS :)
*
* @function t
* @example
* const translatedError = t(`errors.codes.${errorCode}`, {
* defaults: [{ message: t("errors.codes.default") }],
* });
*/
export const t = translate;
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Dobromir Hristov |
| Solution 2 | Victor Molina |
