【发布时间】:2020-09-04 09:23:15
【问题描述】:
我有一个抽象类“Base”
abstract class Base {
constructor(public readonly data: {
[key: string]: BaseValue
}) {}
}
还有一个派生类“Derived”:
class Derived extends Base {
constructor() {
super({
test: SpecialValue
} as const);
}
}
SpecialValue 扩展 BaseValue。
有没有办法在派生类中调用this.data["test"] 并将SpecialValue 作为类型?
我总是得到BaseValue 作为类型。
我不想要的:
在Base 上引入一个泛型类型,该类型的数据字段类型类似于class Derived extends Base<CorrectDataType>。
【问题讨论】:
标签: typescript