我想将具有枚举类型的一个对象的属性映射到具有其他枚举类型的另一个对象的属性。
我尝试过type1.a as Enum2或Enum2[type1.a]没有成功。
这是我的简化代码问题:
enum Enum1 {
N = 0,
A = 1,
B = 2
}
enum Enum2 {
A = 1,
B = 2
}
interface Type1 {
a: Enum1;
}
interface Type2 {
a: Enum2;
}
const type1: Type1 = {
a: Enum1.A
};
const type2: Type2 = {
a: type1.a
};
Run Code Online (Sandbox Code Playgroud)
抛出错误:
Type 'Enum1' is not assignable to type 'Enum2'.
(property) Type2.a: Enum2
Run Code Online (Sandbox Code Playgroud)