Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JSDoc @param together with @deprecated

I have a JavaScript function getting some parameters including object types. However, one property of a parameter, which is an object, will be used as deprecated. I would like to indicate this situation in the documentation, however I don't know how to use @param tag with @deprecated. Consider the example below:

/**
* This function does something.
*
* @name myFunction
* @function
* @since 3.0
* @param {function} [onSuccess] success callback
* @param {function} [onFailure] failure callback
* @param {object} [options] options for function
* @param {string} [options.lang] display language
* @param {string} [options.type] type of sth
*/

this.myFunction= function (onSuccess, onFailure, options) {
    //do something
}

I want to deprecate "type" property of "options" object. How can I do that, or can I?

like image 954
moztemur Avatar asked Apr 21 '15 05:04

moztemur


People also ask

Is JSDoc deprecated?

The require-jsdoc and valid-jsdoc rules will be deprecated. These two rules will remain in ESLint but we will no longer add new features or fix bugs for them. These rules may be removed in a future major release of ESLint.

Can you use JSDoc with TypeScript?

You can use most JSDoc type syntax and any TypeScript syntax, from the most basic like string to the most advanced, like conditional types.

What is JSDoc comment?

JSDoc comments are used for documentation lookup with Ctrl+Q in JavaScript and TypeScript, see JavaScript documentation look-up and TypeScript documentation look-up, as well as for type annotations and method return type hints in chained methods.

Is JSDoc useful?

JsDoc is a great tool for documenting code and providing type-safety in your JavaScript project without any additional configuration. Learn what JsDoc is, how it works, the benefits it provides, and how to use it in your project.


2 Answers

Official JSDoc documentation does not indicate that the @deprecated tag can be used for deprecating anything else than an entire symbol.

The @deprecated tag can be used to document that for example a function as a whole has been deprecated.

/**  * @deprecated since version 2.0.0  */ function old () {  } 

You can of course, as @Droogans said in the comments, add something like deprecated: in front of the @param description. If a developer somehow still ends up using the deprecated feature, you could implement a warning of some sorts.

/**  * @param  {string=} bar - Deprecated: description  */ function foo (bar) {   if (bar) {     console.warn('Parameter bar has been deprecated since 2.0.0')   } } 
like image 145
Sander Avatar answered Sep 29 '22 02:09

Sander


A suggestion is using typescript, like so:

function test(   options: {     /**      * @deprecated use newName instead      */     name?: string,     newName?: string   }) { } 
like image 26
aaron Avatar answered Sep 29 '22 01:09

aaron