I'm restricted to using ES5 (and hence can't use the same solutions as other posts by upgrading to ES6) and have the following code:
let arr = [1,2,1,1,2,3,4]
let arr2 = [].concat([...new Set(arr)])
let arr3 = [...new Set(arr)]
The issue I'm getting is this:
Type 'Set<number>' can only be iterated through when using the '--downlevelIteration' flag or with a '--target' of 'es2015' or higher
Does anyone know how to fix this type? I've tried adding as number[]
but to no avail. I'm not sure what else to do.
Note that this playground can be used to add the code to to see the error: https://playcode.io/typescript