我具有枚举值的接口:
mydriver.ts:
export const enum MyDriverStatus {
DRIVER_DISABLED,
DRIVER_AWAKE,
DRIVER_SLEEP
}
export const enum MyDriverResult {
DRIVER_NONE,
DRIVER_NOK,
DRIVER_OK
}
export default interface MyDriver {
enable: boolean;
status: MyDriverStatus;
result: MyDriverResult ;
value: number;
time: number;
}
在组件方面,我导入了接口:
import { MyDriver, MyDriverStatus, MyDriverResult } from '../interfaces/mydriver';
当我尝试初始化变量时,出现错误:
export class Tab5Page implements OnInit {
drv: MyDriver= {
result: DRIVER_NONE,
status: DRIVER_DISABLED,
value: 0,
time: 0,
enable: false
};
constructor() { }
ngOnInit() {
}
}
找不到名称DRIVER_NONE。
找不到名称DRIVER_DISABLED。
答案 0 :(得分:3)
您需要限定enum
的用法。它们不是隐式的。
result: MyDriverResult.DRIVER_NONE,
status: MyDriverStatus.DRIVER_DISABLED,