【发布时间】:2018-12-07 21:22:47
【问题描述】:
记录泛型类型适用于直接继承。但是当我有一个继承链时,没有办法让它为孙子类工作。这是一个例子:
* @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 仅将返回识别为Red,但不识别DarkRed。有没有办法让它与@template 一起工作?或者有没有其他方法可以让它工作?
我使用 WebStorm 作为 IDE。
【问题讨论】: