如何在TypeScript中将一个Set(例如 {2,4,6})转换为一个数组[2, 4, 6],而不需要显式编写循环?
我尝试了以下这些方法,它们在JavaScript中都有效,但在TypeScript中都无法正常工作。
[...set] // ERR: "Type 'Set<{}>' is not an array type" in typescript
Array.from(set) // ERR: Property 'from' does not exist on type 'ArrayConstructor'
Type 'Set<string>' is not an array type or a string type. Use compiler option '--downlevelIteration' to allow iterating of iterators. ts(2569)
。mayan anger's answer解决了我的问题。 - Joe Sadoski