简体   繁体   中英

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 .

I'm looking at the documentation for @param and I can't see:

  • @param {JSON}

What's the correct approach in JSDoc to indicate a function parameter which must be valid JSON ?

(Surely it's not right to use @param {string} , is it?)

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:

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

and then, later on, use the JSON type in my function definitions etc.

See the line starting with @param below:

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

Further Reading:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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