ES6 Generator support
This can be broken down to 3 areas:
- basic (parser) support, even if we lose typechecking locally
- Typechecking support
- Transpiling like facebook/regenerator or Traceur, for targeting ES3/ES5.
Any timelines on this?
I've been waiting for support for down-level generators in version 1.5, then 1.6, then 2.0, then 2.1.... Now I'm waiting again to hear from the team when they expect it to come. So dissatisfying...
My use case is redux-saga for side-effects and long-lived transactions.
I believe this is on the roadmap, is already merged, and is slated for November 2016 under 2.1. You can probably use these things today by using typescript@next?
https://github.com/Microsoft/TypeScript/wiki/Roadmap
https://github.com/Microsoft/TypeScript/pull/9175
My apologies if I'm missing the point here entirely. It's my understanding that async functions and generators are the same under the hood, but it may only be a subset of generator features that are implemented.
@jocull downlevel generator support has been removed from the roadmap altogether and looks unlikely to be implemented at all - see https://github.com/Microsoft/TypeScript/issues/3975#issuecomment-250859415.
Given that, I'm not sure why this issue is still open or what it is still tracking.
@kdalgaard
I've been waiting for support for down-level generators in version 1.5, then 1.6, then 2.0, then 2.1.... Now I'm waiting again to hear from the team when they expect it to come. So dissatisfying...
Same. Been waiting for this for a long time. And now it's silently not happening? Lame.
I guess for the most part you can develop using generator functions with ES6 output and use Chrome which has native support for generator functions. We have an interesting corner case though. We have a legacy Silverlight application that we are converting to react with redux-saga. So we need to run both SIlverlight and redux-saga on the same page. Silverlight does not run in Chrome, Edge so we cannot use them. Internet Explorer runs Silverlight but does not support generator functions, and since TS does not downcompile to ES5 we cannot use IE. Fortunately for us Firefox supports both SIlverlight and generator functions, however it does not support debugging from Visual Studio.
@jonaskello Would regenerator work? Or does TS do something to the generators when emitting ES5?
Hi @glen-84, Regenerator would work, you can read explanation and check working solution in my starter-kit project here: https://github.com/piotrwitek/react-redux-typescript-starter-kit#asyncawaitgenerators-transformation-when-targeting-es3es5-without-babel
@glen-84 Yupp it would work but then you need to include something like gulp or webpack or babel or something else that multiplies the complexity of the setup. It would be nice to just code Typescript in Visual Studio with full ES2015 support out of the box. Just code some TypeScript, set a breakpoint, hit F5 and off you go. Especially since we have a team that has been doing that for C#/Silverlight. Granted in the end you need bundling for production but it would be nice if not every developer has to learn about these tools.
I wonder if TypeScript could just use regenerator internally? I guess they might want to avoid dependencies though.
@rbuckton can you provide a summary of where we are with this?
@piotrwitek I have read that paragraph of your starter readme over and over, and I still can't see how you would perform the first step, which is compiling TypeScript down to ES5 with generators intact. I believe it will just throw an error when seeing this syntax?
In your starter repo, the compile target for TypeScript is ES6, which won't help at all – Babel will still be needed to transpile it the rest of the way down.
If there exists some way to make TypeScript ignore generators syntax when compiling to ES5, I haven't found it yet 👎
@kdalgaard thanks for pointing that out it means I'll have to add a new paragraph clarifying that which need you to know how plugin-typescript works.
To put it simply there is a seperate TS compiler config for production in jspm.config.js which target ES5. TS will normally emit valid ES5 code with generators passed through thats where regenerator kicks in to finish the job. Now you have valid ES5 with generator functions transpiled.
For development I use only ES6 because you will use evergreen browser anyway for dev so they have native generator support, no need to downlevel that during development and complicate things. Then you will use build script to create ES5 code bundle using ES5 config explained above.
@piotrwitek I wish it were possible, what you describe, but on my machine, when trying to compile a TS script with generators to ES5, errors are emitted in the console, saying that this syntax is not supported for ES5 targets.
You can transpile ts to es6 while editing and configure jspm for babel es6 -> es5 transpilation
On 11 Oct 2016 9:23 PM, "kdalgaard" [email protected] wrote:
@piotrwitek https://github.com/piotrwitek I wish it were possible, what you describe, but on my machine, trying to compile a TS script with generators in it to ES5 results in errors in the console, saying that this syntax is not supported for ES5 targets.
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/Microsoft/TypeScript/issues/1564#issuecomment-252872060, or mute the thread https://github.com/notifications/unsubscribe-auth/ADimvA7snR3nZ-Y6UBx6_pbq0xr7Z4nHks5qy2ORgaJpZM4DMZR_ .
@MaximBalaganskiy The point in question is how to avoid Babel.
Oh, I see. Then Piotr's approach should work. You configure tsconfig for es6 and jspm for es5. Thus no errors in a dev console and right code in browser.
On 11 Oct 2016 9:30 PM, "kdalgaard" [email protected] wrote:
@MaximBalaganskiy https://github.com/MaximBalaganskiy The point in question is how to avoid Babel.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/Microsoft/TypeScript/issues/1564#issuecomment-252873494, or mute the thread https://github.com/notifications/unsubscribe-auth/ADimvBZO2glcCnmKtnV8T_oOrXqg7qSeks5qy2VXgaJpZM4DMZR_ .
@MaximBalaganskiy I completely fail to see where in that description ES6 is compiled to ES5 without the use of Babel.
@kdalgaard I think the confusion here might be that when you use jspm then you do not use tsc at all. Instead something called plugin-typescript is used and it handles the compiling by calling into typescript API. So I guess plugin-typescript just ignores generator functions and outputs them. Then regenerator can run and fix them. If you look as here in @piotrwitek's starter you will see that it actually compiles to es5, but not with tsc, instead plugin-typescript is used as you can see here.
@jonaskello Thanks for that.
I wonder how plugin-typescript is able to use the TypeScript compiler in a way that keeps generators intact.
At any rate, it seems like a pretty flaky strategy from plugin-typescript to just output ES6 syntax even if the target is set to ES5...
@kdalgaard @jonaskello it is working because TypeScript compiler can emit files even when there are errors, so it will emit code compiled to es5 without transpiling generators, but the rest of transformation is good (NOTE: noEmitOnError flag should be false)