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

193
Views
JSDoc generic type - @typedef for WeakRef

How to implement typedef for generic type?

Here is WeakRef typedef:

/**
 * @typedef {Object} WeakRef
 * @property {function(): any} deref
 */

here is using, question inside listing:

export class MyCl {
    /**
     * @type {WeakRef}
    */
    #ref;

    /**
     * @param {HTMLElement} el
    */
    myMethod(el) {
        this.#ref = new WeakRef(el);
    }

    myMethod2() {
        let htmlEl = this.#ref.deref(); // <========
        // htmlEl here is 'any', it must be 'HTMLElement'
    }

I try

/**
 * @typedef {Object} WeakRef
 * @template T
 * @property {function(): T} deref
 */

but don/t know how to setup T here:

/**
 * @type {WeakRef}
 * how to say T is HTMLElement <========
*/
#ref;
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!