如何解决如何使用JSDoc向类中的函数添加参数
让我们把桌子放在这里。
我有一个名为 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?
提前致谢
解决方法
你可以使用typedef
和property
,但是你需要把它写在你使用它的所有文件上,最好使用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) {}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。