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

前端 未结 6 2032
隐瞒了意图╮
隐瞒了意图╮ 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条回答
  •  梦毁少年i
    2021-01-30 06:40

    There's also another way of doing this even though it might be DEPRECATED. Emphasis on might since someone says it's deprecated (check the comments to that answer) while others say either one is fine. I'm reporting it anyway for the sake of completeness.

    Now, take Promise.all() for example which returns a Promise fulfilled with an array. With the dot notation style it would look like shown below:

    {Promise.>}
    

    It works on JetBrains products (e.g. PhpStorm, WebStorm) and it's also used in the jsforce docs.

    At the time of writing when I try to auto-generate some docs with PHPStorm it defaults to this style even though I found poor reference to it.

    Anyway if you take the following function as an example:

    // NOTE: async functions always return a Promise
    const test = async () => { 
        let array1 = [], array2 = [];
    
        return {array1, array2};
    };
    

    When I let PhpStorm generate the docs I get this:

    /**
     * @returns {Promise.<{array1: Array, array2: Array}>}
     */
    const test = async () => {
        let array1 = [], array2 = [];
    
        return {array1, array2};
    };
    

提交回复
热议问题