Posts

Showing posts with the label jsdoc

JSDoc: document generic type that works for grandchildren classes

JSDoc: document generic type that works for grandchildren classes Documenting generic type works for direct inheritance. But when I have a inheritance chain, there is no way to make it work for the grandchildren class. Here is an example: * @property {string} color * @template {T} */ class MyColor { constructor() { this.color = 'unknown'; } /** * @returns {T} */ static makeColor() { return /**@type {T}*/ new this.prototype.constructor(); } } /** * @extends MyColor<Red> * @template {T} */ class Red extends MyColor { constructor() { super(); this.color = 'red'; } } /** * @extends Red<DarkRed> */ class DarkRed extends Red { constructor() { super(); this.level = 2; } darker() { this.level += 1; } } const circle = DarkRed.makeColor(); DarkRed.makeColor only recognizes the return as Red , but not DarkRed . Is there a way to make it work with @template ? Or is there any other way to make it work? Dark...