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

194
Views
¿Cómo usar jsdoc cuando se clasifica en propiedad y cuando se usa Object.assign?

Mi meta

  1. para agregar objetos de tipo definido al crear objetos
  2. los métodos están ocultos en un espacio de nombres

Tengo dos preguntas en el siguiente código.

  1. el tipo de result1 no muestra el tipo completo cuando se usa Object.assign
  2. el tipo de result2 siempre muestra typeof Result, pero espero que sea el tipo de instancia

Explicación del código

Se creará el resultado, al crear necesito agregar A y B_plus (posiblemente otras clases extendidas) y crearé un Objeto nuevo en otros archivos js. No hay forma de usar el módulo en este proyecto.

Si los problemas anteriores no se pueden resolver, ¿cuál es una mejor manera de lograr mi objetivo?

 const Namespace = {}; { class Result {} class A { a; } class B { b; } class B_Plus extends B { bplus; } class Builder { /** * @instance */ result; constructor() { this.result = new Result(); } /** * * @param {A} a */ addA(a) { this.result = Object.assign(this.result, { a }); return this; } /** * * @param {B} b */ addB(b) { this.result = Object.assign(this.result, { b }); return this; } build() { return this.result; } } Namespace.Result = Result; Namespace.A = A; Namespace.B = B; Namespace.B_Plus = B_Plus; Namespace.Builder = Builder; /** * after build, I get {Result}. * this is the way I find to define the type * @type {Result & {a: A, b: B_Plus}} */ let result1 = new Builder() .addA(new A()) .addB(new B_Plus()) .build(); } /** * dont know how to get correct type * at least be {Result} of {Namespace.Result} * but I get {typeof Result} * @type {typeof Namespace.Result} */ let result2 = new Namespace.Builder() .addA(new Namespace.A()) .addB(new Namespace.B_Plus()) .build(); console.log(result2);

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!