I've just started learning JSDoc
and the first stumbling block I've e 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?)
I've just started learning JSDoc
and the first stumbling block I've e 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?)
- 2 JSON text is a string. JsDoc has no syntax to document the format of strings, you need to use the textual description of the parameter for that. – Bergi Commented Dec 12, 2021 at 19:43
-
@Bergi Perhaps I can deploy something like:
@typedef {string} JSON
and then use@param {JSON}
? (See: jsdoc.app/tags-typedef.html) – Rounin Commented Dec 12, 2021 at 19:50
1 Answer
Reset to default 5In 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 pressJSON
* @param {JSON} myJSON - any valid JSON
* @returns {string} a pressed version of the JSON input
*/
Further Reading:
- https://jsdoc.app/tags-typedef.html