【问题标题】:How to add a paramater to a function in a class with JSDoc如何使用 JSDoc 向类中的函数添加参数
【发布时间】:2021-04-27 16:43:40
【问题描述】:

所以让我们在这里设置桌子。

我有一个名为 Command 的类,在该类中我有一个对象作为参数,具有 3 个属性 (name, description, execute())

class Command {
  /**
   *
   * @param {Object} opts
   * @param {String} opts.name
   * @param {String} opts.description
   * @param {Function} opts.execute
   */
  constructor(opts) {
    this.name = opts.name;
    this.description = opts.description;
    this.execute = opts.execute;
  }
}

execute 属性是一个函数,我想为这些函数中的参数传入另一组 JSDoc 行。

它通常应该像这样工作

module.exports = {
  name: "Hello!",
  description: "----",
  /**
   * @param {Message} message
   * @param {Client} client
   * @param {Array} args
   */
  execute(message, client, args) {},
};

是否可以这样做,还是我必须切换到 TypeScript?

提前谢谢你

【问题讨论】:

    标签: javascript node.js discord.js jsdoc


    【解决方案1】:

    你可以使用typedefproperty,但是你需要在你使用它的所有文件上写,最好使用tsconfig.json

    你不需要打字稿,你只需要一个tsconfig.json,当然打字稿会更好。

    https://www.typescriptlang.org/docs/handbook/tsconfig-json.html

    
    /**
     * 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) {}
    

    【讨论】:

    • 如何使用tsconfig.json 方式?很好奇,因为 typescript 文档(特别是 tsconfig.json)中没有提到声明文件
    猜你喜欢
    • 1970-01-01
    • 2016-12-08
    • 1970-01-01
    • 2021-06-01
    • 1970-01-01
    • 1970-01-01
    • 2017-03-25
    • 2021-09-10
    相关资源
    最近更新 更多