question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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:closed
  • Created 4 years ago
  • Comments:9 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
ambroseuscommented, Dec 17, 2019

another solution:

  1. use option "downlevelIteration": true in tsconfig
  2. tsdx build --target node result - es6 as is without transpilation:
const spread = [...
/*#__PURE__*/
new Set([1, 2, 3]), 4, 5];
console.log(spread);
1reaction
ambroseuscommented, Dec 17, 2019

related: https://babeljs.io/docs/en/babel-plugin-transform-spread

"plugins": [
    ["@babel/plugin-transform-spread", {
      "loose": true
    }]
  ]

loose defaults to false. In loose mode true, all iterables are assumed to be arrays.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found