简体   繁体   中英

How to describe other unknown properties in JSDoc

For function below how to express that parameter foo must have property bar of type number but it can also have other properties.

I'd expect that ??? in snippet below can be replaced with meaningful description.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM