6
如何在TypeScript中将Set(例如,{2,4,6})转换为Array [2,4,6]而不显式编写循环?如何将Set转换为TypeScript中的数组
我已经试过那些以下方式,所有的人都在JavaScript中工作,但他们没有对打字稿工作
[...set] // ERR: "Type 'Set<{}>' is not an array type" in typescript
Array.from(set) // ERR: Property 'from' does not exist on type 'ArrayConstructor'
你编译到什么样的目标? Set和Array.from都是在ES6中添加的,并且在编译到ES5时不可用。如果你想使用它们,你可以尝试使用core.js来为它们获取polyfils。 – toskv
@toskv你说得对,当我将目标选项更改为'ES6'时,它工作正常,当前目标是'ES5' – thanhpk