1

I'm pretty sure that [...arguments].map(x => someFunc(x)) works fine in Javascript, but when I try it in Typescript I get the following error:

Type IArguments is not an array type or a string type. Use compiler option --downlevelIteration to allow iterating of iterators.

Does anyone have a clue what is the issue here, and how can I resolve it without changing compiler configuration?

Update

I am able to solve it with Array.from(arguments).map(x => someFunc(x)), but would still be happy to know why the spread operator (...) is not working here.

halfer
  • 19,824
  • 17
  • 99
  • 186
goodvibration
  • 5,980
  • 4
  • 28
  • 61
  • Does this answer your question? [Why \`downlevelIteration\` is not on by default?](https://stackoverflow.com/questions/53441292/why-downleveliteration-is-not-on-by-default) – Mat Sz Jan 29 '20 at 17:06
  • @user1538301: I have no idea what this type is myself, this error just popped up as I used `arguments`, which is a valid expression in Javascript. – goodvibration Jan 29 '20 at 17:06
  • @MatSz: No, it doesn't. My question is why can I not use the spread operator here. – goodvibration Jan 29 '20 at 17:07
  • [It works fine for me](https://www.typescriptlang.org/play/#code/GYVwdgxgLglg9mABMOcAUBKRBvAsAKEUQG0A6cgQwCcBzEAWwFMwoBnAXVPooAc0APRAF4AfIn4YCAXyA) so you should work on producing a [mcve], possibly with compiler options, etc – jcalz Jan 29 '20 at 17:07
  • @goodvibration: it answers why the spread operator is disabled for non-arrays by default. – Mat Sz Jan 29 '20 at 17:07
  • 1
    @MatSz: I take it back. It does pretty much answer my question. Thank you! – goodvibration Jan 29 '20 at 17:08
  • You don't need to turn on `downlevelIteration`.The reason why typescript doesn't know `IArguments` is that you didn't add `es6.iterator` or `esnext` to `compilerOptions.lib` – Equal Jan 30 '20 at 08:18

0 Answers0