Spread syntax can't work with iterables (Set, Map) -- downlevelIteration issue
See original GitHub issue// Input
const set = new Set([1, 2, 3]);
export const spread = [...set, 4, 5];
// Output lib.esm.js
var set =
/*#__PURE__*/
new Set([1, 2, 3]);
var spread =
/*#__PURE__*/
[].concat(set, 4, 5);
export { spread };
//# sourceMappingURL=lib.esm.js.map
Current Behavior
import { spread } from 'lib';
console.log(spread);
// [Set(3), 4, 5]
Expected behavior
import { spread } from 'lib';
console.log(spread);
// [1, 2, 3, 4, 5]
Suggested solution(s)
Additional context
Your environment
Software | Version(s) |
---|---|
TSDX | 0.11.0 |
TypeScript | 3.7.3 |
Browser | Chrome |
npm/Yarn | 6.12.1 |
Node | v13.1.0 |
Operating System | MacOS 10.15 |
Issue Analytics
- State:
- Created 4 years ago
- Comments:9 (6 by maintainers)
Top Results From Across the Web
Using spread syntax and new Set() with typescript
Update: With Typescript 2.3, you can now add "downlevelIteration": true to your tsconfig, and this will work while targeting ES5.
Read more >Spread syntax (...) - JavaScript - MDN Web Docs - Mozilla
The spread (...) syntax allows an iterable, such as an array or string, to be expanded in places where zero or more arguments...
Read more >TSConfig Option: downlevelIteration - TypeScript
This flag is to enable support for a more accurate implementation of how modern JavaScript iterates through new concepts in older JavaScript runtimes....
Read more >Iteration Protocol And Configuring The TypeScript Compiler
This post would be about how to configure the TypeScript compiler in other to be able to work with the iteration protocol. TypeScript...
Read more >Understanding TypeScript Configuration Options
This syntax requires an imported helper but module 'tslib' cannot be found. It will try to import tslib inside the emitted JavaScript so...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
another solution:
"downlevelIteration": true
in tsconfigtsdx build --target node
result - es6 as is without transpilation:related: https://babeljs.io/docs/en/babel-plugin-transform-spread
loose defaults to false. In loose mode true, all iterables are assumed to be arrays.