How to specify resolution and rejection type of the promise in JSDoc?

前端 未结 6 2028
隐瞒了意图╮
隐瞒了意图╮ 2021-01-30 05:56

I have some code that returns a promise object, e.g. using Q library for NodeJS.

var Q = require(\'q\');

/**
 * @returns          


        
6条回答
  •  無奈伤痛
    2021-01-30 07:03

    Syntax currently supported by Jsdoc3:

    /**
     * Retrieve the user's favorite color.
     *
     * @returns {Promise} A promise that contains the user's favorite color
     * when fulfilled.
     */
    User.prototype.getFavoriteColor = function() {
         // ...
    };
    

    Supported in the future?

    /**
     * A promise for the user's favorite color.
     *
     * @promise FavoriteColorPromise
     * @fulfill {string} The user's favorite color.
     * @reject {TypeError} The user's favorite color is an invalid type.
     * @reject {MissingColorError} The user has not specified a favorite color.
     */
    
    /**
     * Retrieve the user's favorite color.
     *
     * @returns {FavoriteColorPromise} A promise for the user's favorite color.
     */
    User.prototype.getFavoriteColor = function() {
        // ...
    };
    

    See github discussion at: https://github.com/jsdoc3/jsdoc/issues/1197

提交回复
热议问题