How to document resolved values of JavaScript promises

后端 未结 2 563
栀梦
栀梦 2021-01-02 03:35

Given this code :

function asyncFoo() {
  return new Promise(function (fulfill, reject) {
    doAsyncStuff(function(err, data) {
      if(err) reject(new Er         


        
相关标签:
2条回答
  • 2021-01-02 04:09

    Looks like you should do the following, based on some other source code's comments.

    /**
     * @return {Promise.<Bar>}
     */
    

    How JavaScript Promises are documented.

    Similar question with a similar answer. Note the lack of a dot in that answer.

    0 讨论(0)
  • 2021-01-02 04:11

    I like to specify that it's an async function with @async and specify the fulfilled return with @returns and error with @throws

    /**
     * @async
     * @returns {Bar}
     * @throws {Error}
     */
    function asyncFoo() { ... }
    
    0 讨论(0)
提交回复
热议问题