【发布时间】:2021-03-20 22:51:21
【问题描述】:
我正在尝试合并枚举映射,代码运行:
enum One {
a = 'a',
}
enum Two {
aa = 'aa',
}
enum Three {
aaa = 'aaa',
}
type unit = One | Two | Three;
const twoFromOne: Map<Two, One> = new Map([[Two.aa, One.a]]);
const threeFromTwo: Map<Three, Two> = new Map([[Three.aaa, Two.aa]]);
const combined: Map<unit, unit> = new Map([
...twoFromOne,
...threeFromTwo,
]);
但我得到一个打字稿编译器错误:
const twoFromOne: Map<Two, One>
No overload matches this call.
Overload 1 of 3, '(iterable: Iterable<readonly [Two, One]>): Map<Two, One>', gave the following error.
Argument of type '([Two, One] | [Three, Two])[]' is not assignable to parameter of type 'Iterable<readonly [Two, One]>'.
The types returned by '[Symbol.iterator]().next(...)' are incompatible between these types.
...
我不明白这个错误,是说一张地图被分配到另一张地图而不是合并?
【问题讨论】:
标签: typescript