JSDoc: Return object structure

后端 未结 3 1955
独厮守ぢ
独厮守ぢ 2020-12-22 17:13

How can I tell JSDoc about the structure of an object that is returned. I have found the @return {{field1: type, field2: type, ...}} description syntax and trie

3条回答
  •  误落风尘
    2020-12-22 17:53

    A clean solution is to write a class and return that.

    /** 
     *  @class Point
     *  @type {Object}
     *  @property {number} x The X-coordinate.
     *  @property {number} y The Y-coordinate.
     */
    function Point(x, y) {
      return {
            x: x,
            y: y
        };
    }
    
    /**
     * @returns {Point} The location of the event.
     */
    var getEventLocation = function(e, type) {
        ...
        return new Point(x, y);
    };
    

提交回复
热议问题