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;