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

前端 未结 5 394
春和景丽
春和景丽 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条回答
  •  半阙折子戏
    2020-12-02 15:38

    As of late 2014 in jsdoc3 you have the possibility to write:

    /**
     * @param {('rect'|'circle'|'ellipse')} shapeType - The allowed type of the shape
     */
    Shape.prototype.getType = function (shapeType) {
      return this.type;
    };
    

    Of course this will not be as reusable as a dedicated enum but in many cases a dummy enum is an overkill if it is only used by one function.

    See also: https://github.com/jsdoc3/jsdoc/issues/629#issue-31314808

提交回复
热议问题