我使用Constrained Mixins,当我试图访问test()
函数中未定义的属性a
时,没有引发错误,它应该引发错误TS2339: Property a does not exist on type A
,为什么不发生呢?
export function withBindable<T extends new (...args: any[]) => any>(BaseType: T) {
return class extends BaseType {
public mixin = 1;
};
}
class Base{
public b = 2;
}
class A extends withBindable(Base){
public test(){
this.mixin = 2; // OK
this.b = 3; // OK
this.a = 2; // should raise an error, but no error raised, tsc will compile this code successfully, and typeof this.a is any
}
}