How to describe a returned promise in a function annotation?

When writing JavaScript code, I always comment on my functions as described here , for example:

/**
 * Add two values
 * @param {Number} a
 * @param {Number} b
 * @returns {Number} the sum of a and b
 */
function add(a, b) {
  return a + b;
}

Now, when I write an asynchronous function returning Promise, it will be:

/**
 * Add two values
 * @param {Number} a
 * @param {Number} b
 * @returns {Promise} the sum of a and b
 */
function add(a, b) {
  return new Promise(function (resolve, reject) {
    resolve(a + b);
  });
}

But now the description of the return type ( Promise) skips information about what type of promise will be returned when it is resolved.

How to indicate that the promised promise will be resolved with Number?

I would think that it is Promise.<Number>better (similarly Array.<Number>), but in this area there is no ordinary practice.

+4
source share
1 answer

generics. jsdoc , .

: Promise.<number>.

Promise.<number, Error> , , - otoh, , , . - . , , .

+6

Source: https://habr.com/ru/post/1533165/


All Articles