How to document a string type in jsdoc with limited possible values

前端 未结 5 382
春和景丽
春和景丽 2020-12-02 15:08

I am having a function that accepts one string parameter. This parameter can have only one of a few defined possible values. What is the best way to document the same? Shoul

5条回答
  •  -上瘾入骨i
    2020-12-02 15:29

    I don't think there's a formal way of writing allowed values in JSDoc.

    You certainly can write something like @param {String('up'|'down'|'left'|'right')} like user b12toaster mentioned.

    But, by taking reference from APIDocjs, here's what I use for writing constrained values, aka allowedValues.

    /**
     * Set the arrow position of the tooltip
     * @param {String='up','down','left','right'} position pointer position
     */
    setPosition(position='left'){
      // YOUR OWN CODE
    }
    

    Oh yeah, I'm using ES6.

提交回复
热议问题