Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 519
dimlucas Avatar asked Sep 18 '25 05:09

dimlucas


1 Answers

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
like image 136
Lajos Gallay Avatar answered Sep 19 '25 18:09

Lajos Gallay