Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

196
Vistas
En el archivo Javascript, cómo comentar la firma de la función de sobrecarga en tsdoc/jsdoc (puede ser reconocido por vscode intellisense)

Tengo estas definiciones:

 class Entity {} class Point {} class Edge {} class A { from(x, y) { if (x == null) { return this.remember('_from') } else if (x instanceof Entity || x instanceof Point) { this.remember('_from', new Edge(x)) return this } else { this.remember('_from', new Edge(new Point(x, y))) return this } } }

El método from tiene varias firmas, como se muestra arriba. Quiero escribir el comentario jsdoc sobre él para usar vscode intellisense.

Tengo dos formas de hacerlo, pero ninguna de ellas funciona:

 class A { /** * @type {((x: number, y: number) => this) & ((x: Entity|Point) => this) & (() => Edge)} */ from(x, y) { if (x == null) { return this.remember('_from') } else if (x instanceof Entity || x instanceof Point) { this.remember('_from', new Edge(x)) return this } else { this.remember('_from', new Edge(new Point(x, y))) return this } } }
 class A { /** * @template T * @typedef {{ * (this: T, x: number, y: number): T; * (this: T, entity: Entity): T; * (this: T, point: Point): T; * (): Edge; * }} fromType * * @type {fromType<this>} */ from(x, y) { if (x == null) { return this.remember('_from') } else if (x instanceof Entity || x instanceof Point) { this.remember('_from', new Edge(x)) return this } else { this.remember('_from', new Edge(new Point(x, y))) return this } } }

Ahora tengo una solución alternativa, pero no es una sobrecarga, ya que el parámetro x no se puede solicitar con el tipo exacto.

 class A { /** * @template {unknown} T * @param {T} [x] * @param {number} [y] * @returns {T extends Entity|Point|number ? this : Edge} */ from(x, y) { if (x == null) { return this.remember('_from') } else if (x instanceof Entity || x instanceof Point) { this.remember('_from', new Edge(x)) return this } else { this.remember('_from', new Edge(new Point(x, y))) return this } } }

Entonces, ¿hay alguna manera de escribir la sobrecarga correcta de la firma de la función en tsdoc y cómo escribirla en caso afirmativo? Gracias.

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda