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

126
Vistas
jsDoc : How do I make the @return type of my method the type of a local variable from it?

I'm making a javascript project and I want to make it as clean as possible, and for that I'm using jsDoc at the top of my methods. For one of them, I would like to know if it's possible to specify as a return type the type of a local variable ?

Like this :

/**
* Add a component to the gameObject
* @param {Function} component to add
* @return {comp.constructor.name}
*/
addComponent(component){
    let comp = eval("new Tzu." + component.name + "({gameObject : this});");
    this.behaviors.push(comp);

    return comp;
} 

I want the @return to be the type of comp

Of course the line 4 is completely wrong

Thanks !

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You should be able to do something like

let test = 'test';

/**
 * @returns {typeof test}
 */
function doSomething(test) {
    return test;
}

As a side note, you really shouldn't use eval. See this for more information.

about 4 years ago · Juan Pablo Isaza Denunciar
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