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

125
Views
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 answers
Answer question

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 Report
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!