简体   繁体   English

如何在 JSDoc 中记录 JSON 参数?

[英]How to document a JSON parameter in JSDoc?

I've just started learning JSDoc and the first stumbling block I've come across is how to indicate a function parameter which must be valid JSON .我刚刚开始学习JSDoc ,遇到的第一个障碍是如何指示function 参数,该参数必须是有效JSON

I'm looking at the documentation for @param and I can't see:我正在查看@param的文档,但看不到:

  • @param {JSON}

What's the correct approach in JSDoc to indicate a function parameter which must be valid JSON ? JSDoc中指示function 参数的正确方法是什么,该参数必须是有效JSON

(Surely it's not right to use @param {string} , is it?) (当然使用@param {string}是不对的,是吗?)

In the absence of any other answers so far, I'm going to go with defining JSON as a type at the top of the javascript file, like this:到目前为止,在没有任何其他答案的情况下,我将使用 go 将JSON定义为 javascript 文件顶部的类型,如下所示:

/**
 * Define JSON
 * @typedef {string} JSON
 */

and then, later on, use the JSON type in my function definitions etc.然后,稍后,在我的 function 定义等中使用JSON类型。

See the line starting with @param below:请参阅下面以@param开头的行:

/**
 * Compresses JSON data
 * @function compressJSON
 * @param {JSON} myJSON - any valid JSON
 * @returns {string} a compressed version of the JSON input
 */

Further Reading:延伸阅读:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM