dimlucas
dimlucas

Reputation: 5141

Multiple lines in JSDoc object definition

I am a facade NodeJS module that simplifies interaction with the Shopify API for my backend's needs. I have a function that returns a promise that when resolved, contains an object with the shop's details (id, email, country, currency, etc).

I want to use JSDoc to document those properties to make the life of our devs easier (we are all using VSCode and Intellisense picks up JSDoc type definitions with zero config).

Unfortunately, the fields list returned by that API call is huge so I end up with a single line spanning multiple columns looking like this:

@return {Promise<{id, name, email, domain, province, country, address1, zip, city, source, phone, latitude, longitude, primary_locale, address2, created_at, updated_at, country_code, country_name, currency, customer_email, timezone, shop_owner, money_format, weight_unit, province_code, taxes_included.....

Is there a way to break this into separate lines and maintain both VSCode syntax highlight in the JSDoc and working Intellisense?

Upvotes: 4

Views: 1529

Answers (3)

xmedeko
xmedeko

Reputation: 7820

VS Code 1.97 (Jan 2025) has no problem when you break JSDoc @param or @returns on multiple lines:

/**
 * @returns {Promise<{id, name, 
 *      email, domain}>} Returns my object.
 */

Or, as a workaround, define new JSDoc type

/**
 * @typedef {object} MyReturnType
 * @property {number} id
 * @property {name} id
 * @property {string} email
 * ...
 * @returns {Promise<MyReturnType>}
 */

Upvotes: 0

user21512215
user21512215

Reputation: 11

I know the question has been asked long ago meanwhile, but I found a solution that might be interesting fo other users:

Simply put a <br> tag between the items you want to display in a new line. It works in the VS Code as well as in the created documentation!

Upvotes: 1

Lajos Gallay
Lajos Gallay

Reputation: 1317

If you are using typescript (I assume that from the generic definition) I'd suggest to extract the generic type into a separate interface:

/**
 * Return type of something
 */
interface PromiseReturnType {
    /**
     * The unique identifyer
     */
    id: number
    /**
     * JSDoc hint for the name
     */
    name: string
}

const a: Promise<PromiseReturnType> = new Promise(...)
const props = await a
props.id // you will get the hint here

Upvotes: 1

Related Questions