JSDoc中文文档(@use JSDoc)

JSDoc @typedef 标签



@typedef [<type>] <namepath>


The @typedef tag is useful for documenting custom types, particularly if you wish to refer to them repeatedly. These types can then be used within other tags expecting a type, such as @type or @param.

Use the @callback tag to document the type of callback functions.





示例: 使用 @typedef 标签
 * A number, or a string containing a number.
 * @typedef {(number|string)} NumberLike

 * Set the magic number.
 * @param {NumberLike} x - The magic number.
function setMagicNumber(x) {

本实例定义了一个更复杂的类型,一个对象的几个属性,并设置其namepath(名称路径) 所以使用该类型将与类一起显示。由于该类型定义实际上不是由类暴露, 习惯上,以记录类型定义作为内部构件。

示例: 使用@typedef记录的复杂类型的一类
 * The complete Triforce, or one or more components of the Triforce.
 * @typedef {Object} WishGranter~Triforce
 * @property {boolean} hasCourage - Indicates whether the Courage component is present.
 * @property {boolean} hasPower - Indicates whether the Power component is present.
 * @property {boolean} hasWisdom - Indicates whether the Wisdom component is present.

 * A class for granting wishes, powered by the Triforce.
 * @class
 * @param {...WishGranter~Triforce} triforce - One to three {@link WishGranter~Triforce} objects
 * containing all three components of the Triforce.
function WishGranter(triforce) {}