Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VSCode: How to document promise that resolves with complex object?

I have a function f that returns a Promise. The returned Promise either resolve({name: String, data: Object}) or reject(Error).

I've tried the following syntax(as mentioned in an issue in JSDoc) in VSCode, but it doesn't work:

/**
 * @promise fPromise
 * @reject {Error}
 * @fulfill {Object} project
 * @fulfill {Object} project.data
 * @fulfill {String} project.name
 * @returns fPromise
*/
like image 326
lz96 Avatar asked Aug 10 '17 12:08

lz96


1 Answers

I think your best bet is to wrap your fulfill response into a custom object:

/**
 * @promise fPromise
 * @reject {Error}
 * @fulfill {Project}
 * @returns {Promise.<Project>}
*/
function renderResults(data) {
    return new Promise((resolve, reject) => {
        resolve(new Project())
    })
}

renderResults()

function Project() {
    this.data = "data";
    this.name = "project phoenix"
    this.location = {
        city: 'seattle',
        state: 'wa'
    }
}

This will show in VS Code like this:

enter image description here

like image 79
Maria Ines Parnisari Avatar answered Sep 29 '22 09:09

Maria Ines Parnisari