我不明白为什么在我的Angular 项目中,当我试图将值设置为testObject
时,打字错误Type boolean is not assignable to type never
.
export interface TestInterface {
text: string;
number: number;
bool1: boolean;
bool2: boolean;
}
export class DamagesComponent implements OnInit {
testObject: TestInterface = {
text: 'test String',
number: 22,
bool1: false,
bool2: true
}
ngOnInit() {
this.toogleVal('bool1')
}
toogleVal(key: keyof TestInterface): void {
if (key in this.testObject) {
if (typeof this.testObject[key] === 'boolean') {
// here the error
this.testObject[key] = true;
}
}
}
}