数字枚举与数值兼容
enum Gender {
Male,
Female
}
let value: Gender;
value = Gender.Male;
value = 1;
console.log(value);
数字枚举与数字枚举不兼容
enum Gender {
Male,
Female
}
enum Animal {
Dog,
Cat
}
let value: Gender;
value = Gender.Male;
console.log(value);
// 如下????代码会报错
value = Animal.Dog;
console.log(value);
字符串枚举与字符串不兼容
enum Gender {
Male = 'abc',
Female = 'def'
}
let value: Gender;
value = Gender.Male;
// 如下????代码会报错
value = 'abc';
console.log(value);