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

200
Vistas
In Javascript file, How to comment overloading function signature in tsdoc/jsdoc(can be recognized by vscode intellisense)

I have these definitions:

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
    }
  }
}

The from method has multiple signature as shown above. I want to write the jsdoc comment on it for vscode intellisense using.

I have two ways of it, but neither of them is worked:


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
    }
  }
}

I have now a workround, but it's not an overloading, since the parameter x can not be prompted with exact type.


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
    }
  }
}

So is there a way to write correct overloading of function signature in tsdoc and how to write it if yes? Thank you.

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