6

I'm using JSDoc and I would like to add the info to my documentation which value a parameter should have.

In this example you can see, that the parameter operator has string type. But furthermore there can only be open or close as valid value of the parameter

/**
 * Description
 * @param {string='open','close'}  operator
 */

What is the correct syntax to add this information?

user3142695
  • 15,844
  • 47
  • 176
  • 332

2 Answers2

18

Use a type union |:

/**
 * Description
 * @param {('open'|'close')}  operator
 */
CRice
  • 29,968
  • 4
  • 57
  • 70
0

From a design perspective, if your pram is restricted to a list of options you should create an Enum of those options for reusability. see this answer for details: https://stackoverflow.com/a/19322623/5633515

Alternatively, you can create wrapper functions like

_changeState(state){...} // assumed private
close(){ _changeState('close')}
open(){_changeState('open')}
Ahmed Musallam
  • 9,523
  • 4
  • 27
  • 47