Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

170
Views
¿Cómo describir con JSDoc una función que devuelve el mismo objeto estructurado que toma como argumento, pero algunas propiedades tendrán un tipo diferente?

Necesito documentar una función que devuelve un objeto con la misma estructura que pasó el usuario, pero los tipos de campos son diferentes.

 class CoolThing { constructor (id, settings) { } happyLittleMethod () { /* do something */ } } /** * This definition says that an object returns ALMOST the same structure that passed. * Feels close. * * @template T * @param {T} ABThingsAndStuff * @returns {T} */ function makeSomeThings ({ thingsA, thingsB, ...otherStuff }) { const a = {} const b = {} for (let key in thingsA) { a[key] = new CoolThing(key, thingsA[key]) } for (let key in thingsB) { b[key] = new CoolThing(key, thingsB[key]) } return { thingsA: a, thingsB: b, ...otherStuff } }

Entonces alguien puede usar una función como esta:

 const myThings = makeSomeThings({ thingsA: { cat: 1, dog: 2, }, thingsB: { bone: 3, apple: 4, }, worldName: 'Pretty strange place', })

myThings autocompleta todo, desde la carga útil del usuario, sin embargo, algunas partes internas de los objetos ahora tienen un tipo diferente.

 myThings.thingsA.cat.happyLittleMethod() // ^ // how can I autocomplete this happyLittleMethod?
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!