【问题标题】:How to describe other unknown properties in JSDoc如何在 JSDoc 中描述其他未知属性
【发布时间】:2021-07-29 05:20:47
【问题描述】:

对于下面的函数,如何表达参数foo必须有bar类型的number属性,但它也可以有其他属性。

我希望下面 sn-p 中的 ??? 可以替换为有意义的描述。

/**
 * @param {{bar: number, ???}} foo
 * @return {{bar: number, ???}} parameter `foo` with incremented property `bar`
 */
function fn(foo) {
    const { bar, ...rest } = foo
    console.log('bar', bar)
    console.log('other unknown properties', rest)

    foo.bar++
    return object
}

【问题讨论】:

    标签: javascript jsdoc


    【解决方案1】:
    /**
     * 
     * @param {{bar: number, [p:string]:any}} foo
     * @return {{bar: number, [p:string]:any}}
     */
    function fun(foo) {
      const { bar, ...rest } = foo
      console.log('bar', bar)
      console.log('other unknown properties', rest)
    
      foo.bar++
      return foo
    }
    

    【讨论】:

    猜你喜欢
    • 2021-03-09
    • 2011-09-21
    • 2020-07-15
    • 2014-12-07
    • 2017-02-17
    • 2017-05-19
    • 2017-11-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多