非平凡ES6代码的文档示例

时间:2017-11-16 12:04:02

标签: javascript reactjs ecmascript-6 jsdoc ecmascript-7

我很难找到合适的文档样本/文档ES6代码的引用,比如ES6文档的某种备忘单。

我想在JSDoc文档上保持一致,但是在这个问题的最常见答案中,我只能设法找到琐碎的代码文档,而不是适合新ES6 + /的文档反应语法或更复杂的参数,如数组,映射,参数反序列化等。

例如does-javascript-have-a-standard-for-commenting-functions仅提供有关标准参数的常规JS函数的文档示例。

我想找到规则/好方法来记录这样的事情,如何表明需要或不需要的参数等等。

方法I的例子,想要记录

const signInWithCredentials = ({ emails, password, authentication_code }, options) => {

}

我可以想到这样的事情

**
 * Attempts sign in with any possible credentials pair
 * (Provide either email + password, or an authentication_code and a provider name in the options
 * @param { 
 *   emails: { Array<String> },
 *   password: { String },
 *   authentication_code: { String }
 * } - credentials
 * @param { Object } - options
 * @param { String } - options.provider

但我不确定如何处理不具有名称function({ param1, param2 }),嵌套function({ param1: { nestedParam1, nestedParam2 })或重命名为function({ param1: name1 })的反序列化参数以及如何处理组合类型,如xxx数组

我已经在使用PropTypes进行了多次方法声明,但它们只在使用React组件时才有效,但在编写实用函数等时不太有用。

1 个答案:

答案 0 :(得分:1)

没关系,我刚刚意识到JSDoc有一个带有文档样本的官方页面,其中包含了一个关于破坏的部分

http://usejsdoc.org/tags-param.html

Documenting a destructuring parameter
/**
 * Assign the project to an employee.
 * @param {Object} employee - The employee who is responsible for the project.
 * @param {string} employee.name - The name of the employee.
 * @param {string} employee.department - The employee's department.
 */
Project.prototype.assign = function({ name, department }) {
    // ...
};
相关问题