TypeScript Compiler - Why downlevelIteration is not on by default?
When targeting like ES5 with usage of spread operator ...
to convert an Iterator to an Array, it shows the error to use -downlevelIteration
compiler option. Once it is on, spread operators seem just work flawlessly. I wonder why is there a need to specify this?
Are there any downsides/limitation when it is enabled besides adding more emitted generated code from tslib?
Without -downlevelIteration
enabled by default in the TypeScript Playground spread operators can't be fully tested.
Another example: Dynamically create array of N (eg. 3):
[...Array(3).keys()] // output: [0, 1, 2]
Error display in VS Code:
Error message from tsc
:
Type 'IterableIterator' is not an array type or a string type. Use compiler option '--downlevelIteration' to allow iterating of iterators.
Edit and view the code and error in TypeScript Playground
typescript
add a comment |
When targeting like ES5 with usage of spread operator ...
to convert an Iterator to an Array, it shows the error to use -downlevelIteration
compiler option. Once it is on, spread operators seem just work flawlessly. I wonder why is there a need to specify this?
Are there any downsides/limitation when it is enabled besides adding more emitted generated code from tslib?
Without -downlevelIteration
enabled by default in the TypeScript Playground spread operators can't be fully tested.
Another example: Dynamically create array of N (eg. 3):
[...Array(3).keys()] // output: [0, 1, 2]
Error display in VS Code:
Error message from tsc
:
Type 'IterableIterator' is not an array type or a string type. Use compiler option '--downlevelIteration' to allow iterating of iterators.
Edit and view the code and error in TypeScript Playground
typescript
The generated code is pretty ugly as well
– Titian Cernicova-Dragomir
Nov 23 '18 at 6:25
add a comment |
When targeting like ES5 with usage of spread operator ...
to convert an Iterator to an Array, it shows the error to use -downlevelIteration
compiler option. Once it is on, spread operators seem just work flawlessly. I wonder why is there a need to specify this?
Are there any downsides/limitation when it is enabled besides adding more emitted generated code from tslib?
Without -downlevelIteration
enabled by default in the TypeScript Playground spread operators can't be fully tested.
Another example: Dynamically create array of N (eg. 3):
[...Array(3).keys()] // output: [0, 1, 2]
Error display in VS Code:
Error message from tsc
:
Type 'IterableIterator' is not an array type or a string type. Use compiler option '--downlevelIteration' to allow iterating of iterators.
Edit and view the code and error in TypeScript Playground
typescript
When targeting like ES5 with usage of spread operator ...
to convert an Iterator to an Array, it shows the error to use -downlevelIteration
compiler option. Once it is on, spread operators seem just work flawlessly. I wonder why is there a need to specify this?
Are there any downsides/limitation when it is enabled besides adding more emitted generated code from tslib?
Without -downlevelIteration
enabled by default in the TypeScript Playground spread operators can't be fully tested.
Another example: Dynamically create array of N (eg. 3):
[...Array(3).keys()] // output: [0, 1, 2]
Error display in VS Code:
Error message from tsc
:
Type 'IterableIterator' is not an array type or a string type. Use compiler option '--downlevelIteration' to allow iterating of iterators.
Edit and view the code and error in TypeScript Playground
typescript
typescript
edited Mar 11 at 18:48
Beau Smith
21.5k64962
21.5k64962
asked Nov 23 '18 at 5:54
CerlancismCerlancism
3816
3816
The generated code is pretty ugly as well
– Titian Cernicova-Dragomir
Nov 23 '18 at 6:25
add a comment |
The generated code is pretty ugly as well
– Titian Cernicova-Dragomir
Nov 23 '18 at 6:25
The generated code is pretty ugly as well
– Titian Cernicova-Dragomir
Nov 23 '18 at 6:25
The generated code is pretty ugly as well
– Titian Cernicova-Dragomir
Nov 23 '18 at 6:25
add a comment |
1 Answer
1
active
oldest
votes
After reading the release notes and the article TypeScript 2.3: Downlevel Iteration for ES3/ES5, I believe the answer to this question is that downlevelIteration
is disabled because you need to decide (via configuration) how you want TypeScript to handle the compilation of compatibility code (to support older versions of Javascript).
As the more lengthy explanation in the article makes clear, you have to make a decision as to if you want TypeScript to inline necessary helper functions (simple, but can result in larger production bundle size) or if you wish to configure TypeScript to use tslib
as a dependency and then make calls to its external methods.
I highly recommend reading TypeScript 2.3: Downlevel Iteration for ES3/ES5 for a deeper understanding… and possibly an alternate solution to your initial issue.
As for why downlevelIteration
is not an option in the TypeScript Playground, I'm not sure. The Playground is open source, so you can definitely create a submit a pull request… and doing so may get an even better answer than this one!
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53441292%2ftypescript-compiler-why-downleveliteration-is-not-on-by-default%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
After reading the release notes and the article TypeScript 2.3: Downlevel Iteration for ES3/ES5, I believe the answer to this question is that downlevelIteration
is disabled because you need to decide (via configuration) how you want TypeScript to handle the compilation of compatibility code (to support older versions of Javascript).
As the more lengthy explanation in the article makes clear, you have to make a decision as to if you want TypeScript to inline necessary helper functions (simple, but can result in larger production bundle size) or if you wish to configure TypeScript to use tslib
as a dependency and then make calls to its external methods.
I highly recommend reading TypeScript 2.3: Downlevel Iteration for ES3/ES5 for a deeper understanding… and possibly an alternate solution to your initial issue.
As for why downlevelIteration
is not an option in the TypeScript Playground, I'm not sure. The Playground is open source, so you can definitely create a submit a pull request… and doing so may get an even better answer than this one!
add a comment |
After reading the release notes and the article TypeScript 2.3: Downlevel Iteration for ES3/ES5, I believe the answer to this question is that downlevelIteration
is disabled because you need to decide (via configuration) how you want TypeScript to handle the compilation of compatibility code (to support older versions of Javascript).
As the more lengthy explanation in the article makes clear, you have to make a decision as to if you want TypeScript to inline necessary helper functions (simple, but can result in larger production bundle size) or if you wish to configure TypeScript to use tslib
as a dependency and then make calls to its external methods.
I highly recommend reading TypeScript 2.3: Downlevel Iteration for ES3/ES5 for a deeper understanding… and possibly an alternate solution to your initial issue.
As for why downlevelIteration
is not an option in the TypeScript Playground, I'm not sure. The Playground is open source, so you can definitely create a submit a pull request… and doing so may get an even better answer than this one!
add a comment |
After reading the release notes and the article TypeScript 2.3: Downlevel Iteration for ES3/ES5, I believe the answer to this question is that downlevelIteration
is disabled because you need to decide (via configuration) how you want TypeScript to handle the compilation of compatibility code (to support older versions of Javascript).
As the more lengthy explanation in the article makes clear, you have to make a decision as to if you want TypeScript to inline necessary helper functions (simple, but can result in larger production bundle size) or if you wish to configure TypeScript to use tslib
as a dependency and then make calls to its external methods.
I highly recommend reading TypeScript 2.3: Downlevel Iteration for ES3/ES5 for a deeper understanding… and possibly an alternate solution to your initial issue.
As for why downlevelIteration
is not an option in the TypeScript Playground, I'm not sure. The Playground is open source, so you can definitely create a submit a pull request… and doing so may get an even better answer than this one!
After reading the release notes and the article TypeScript 2.3: Downlevel Iteration for ES3/ES5, I believe the answer to this question is that downlevelIteration
is disabled because you need to decide (via configuration) how you want TypeScript to handle the compilation of compatibility code (to support older versions of Javascript).
As the more lengthy explanation in the article makes clear, you have to make a decision as to if you want TypeScript to inline necessary helper functions (simple, but can result in larger production bundle size) or if you wish to configure TypeScript to use tslib
as a dependency and then make calls to its external methods.
I highly recommend reading TypeScript 2.3: Downlevel Iteration for ES3/ES5 for a deeper understanding… and possibly an alternate solution to your initial issue.
As for why downlevelIteration
is not an option in the TypeScript Playground, I'm not sure. The Playground is open source, so you can definitely create a submit a pull request… and doing so may get an even better answer than this one!
edited Mar 11 at 21:02
answered Mar 11 at 18:37
Beau SmithBeau Smith
21.5k64962
21.5k64962
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53441292%2ftypescript-compiler-why-downleveliteration-is-not-on-by-default%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
The generated code is pretty ugly as well
– Titian Cernicova-Dragomir
Nov 23 '18 at 6:25