Your StringAttributes
requires typescript to fully evaluate keyof this
, which it can't do. Instead, use a generic with a bound:
doStuff<T extends keyof this & string>(attr: T): void {
console.log(this[attr]);
}
Or, as stated in the comments:
doStuff(attr: keyof this & string): void {
console.log(this[attr]);
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…