【问题标题】:Multiple lines in JSDoc object definitionJSDoc 对象定义中的多行
【发布时间】:2018-04-12 09:33:03
【问题描述】:

我是一个外观 NodeJS 模块,它简化了与 Shopify API 的交互以满足我的后端需求。我有一个函数,它返回一个承诺,当它被解决时,它包含一个带有商店详细信息(id、电子邮件、国家、货币等)的对象。

我想使用 JSDoc 来记录这些属性,以使我们的开发人员的生活更轻松(我们都在使用 VSCode,而 Intellisense 采用零配置的 JSDoc 类型定义)。

不幸的是,该 API 调用返回的字段列表很大,所以我最终得到一个跨越多个列的单行,如下所示:

@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.....

有没有办法将其分成单独的行并同时保持 JSDoc 中的 VSCode 语法高亮和正常工作的 Intellisense?

【问题讨论】:

    标签: node.js visual-studio-code shopify jsdoc


    【解决方案1】:

    如果您使用的是打字稿(我假设来自泛型定义),我建议将泛型类型提取到单独的接口中:

    /**
     * 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
    

    【讨论】:

    • 不,就是这样。我没有使用 TypeScript。它是纯 JavaScript,我只需要它用于少数返回具有许多属性的对象的方法
    猜你喜欢
    • 2017-02-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多