TypeScript icon indicating copy to clipboard operation
TypeScript copied to clipboard

ES6 Generator support

Open wizzard0 opened this issue 11 years ago • 70 comments

This can be broken down to 3 areas:

  1. basic (parser) support, even if we lose typechecking locally
  2. Typechecking support
  3. Transpiling like facebook/regenerator or Traceur, for targeting ES3/ES5.

Any timelines on this?

wizzard0 avatar Dec 26 '14 15:12 wizzard0

We have basic parser support (#1268). As our roadmap specifies, 1.5 is the target for emit, though I'm not sure if that includes the ES3/ES5 polyfill.

Since I don't see an official issue tracking it, I think this might be a good candidate!

DanielRosenwasser avatar Dec 27 '14 05:12 DanielRosenwasser

Please take a look at #2873 and let me know if this addresses your needs.

JsonFreeman avatar Apr 27 '15 19:04 JsonFreeman

I've just seen that the TypeScript 2.0 milestone was added to support transpiling generators to ES5: do you have any estimate when it will be released?

buzinas avatar Apr 04 '16 06:04 buzinas

@buzinas I don't know when to expect it but until then the workaround is to get TypeScript code with async/await transpiled to ES6 and then in a second build step use Babel to transpile that to ES5.

omidkrad avatar May 13 '16 01:05 omidkrad

@omidkrad Yeah, I know that, did this for one project, but for the others, I'm trying to keep things dry, so, I'm using only TypeScript as transpiler.

For bigger projects, the build time of two transformations doesn't compensate for us. Also, the sourcemaps don't work well when transpiling two times, unfortunately (they work, but poorly sometimes).

At the moment, we're sticking with promises, and it's good enough for 90% of the cases.

buzinas avatar May 13 '16 01:05 buzinas

I think we'll have a beta ready to use towards late May/early July, though no promises on dates.

DanielRosenwasser avatar May 13 '16 06:05 DanielRosenwasser

@omidkrad For me using Babel just for transpiling async/await to ES5 was a a little bit of overkill, so for that workaround in my projects I'm currently using https://github.com/facebook/regenerator, works fine, but I cannot wait to finally have it possible by only using TS

piotrwitek avatar May 13 '16 12:05 piotrwitek

@piotrwitek Nice tip! Do you run generator on tsc's ES5 output?

omidkrad avatar May 13 '16 20:05 omidkrad

@omidkrad yes "target": "es5", then I'm running regenerator -r app.ts-es5.js > app.es5.js, I needed this mainly because of IE10+ support and it's working fine, just need to include ES6 shim for Promises

piotrwitek avatar May 15 '16 13:05 piotrwitek

@piotrwitek I'm missing something - how do you get tsc to compile your code to es5 in the first place if you have async/await syntax in there?

vigie avatar May 18 '16 01:05 vigie

@vigie Actually it's really good question, when using compiler you got async compilation error (Async functions are only available when targeting ECMAScript 6 and higher.), but transpiled code using generator functions is still emitted just fine, in Atom I'm using target es6 for eslint and typescript compile but with noEmit flag so normally I don't see any of these errors during development, then down my workflow I'm using SystemJS/JSPM to build bundle with target es5, on bundle step I don't have to care anymore about compiler errors

piotrwitek avatar May 18 '16 13:05 piotrwitek

@piotrwitek A very interesting technique, thanks for taking the time to explain it. I'm currently evaluating introducing Babel into the chain, but its great to know you have had success with this lighter weight option.

vigie avatar May 19 '16 23:05 vigie

it's late may and still no promises, learn to type faster! :stuck_out_tongue_winking_eye:

zpdDG4gta8XKpMCd avatar May 25 '16 20:05 zpdDG4gta8XKpMCd

Big +1 on this feature. With this feature, my team's development flow could be 100% integrated inside VS2015. Currently, because we need generator functions, we need to introduce double compiling with babel and loose a lot of VS2015 integration (compile on save, error reporting, and debugging). Really looking forward to using this feature once it is implemented.

jonaskello avatar Jun 22 '16 06:06 jonaskello

Is this still on track for TypeScript 2.0? The implementing PR #9175 for this depends on the new emitter #5595, but the milestone of the latter has been updated to 2.1.

I'd appreciate it if one of the core contributors could update the roadmap and the issues linked in the roadmap with the correct milestones. It'd help get a better idea what to expect in 2.0, because right now there's a lot of conflicting information.

MattiasBuelens avatar Jul 01 '16 13:07 MattiasBuelens

2.0 or 2.1 ?

WanderWang avatar Jul 10 '16 14:07 WanderWang

Do not release TS 2.0 without async / await for ES5/3, the main feature. Otherwise it will be ridiculous.

vbcodec avatar Jul 11 '16 09:07 vbcodec

@vbcodec I want it just as much as you do, but there is lots of new stuff in 2.0, so it wouldn't be "ridiculous" – maybe just disappointing.

glen-84 avatar Jul 11 '16 10:07 glen-84

It'd just be nice to have some indication from 'those in the know' what is happening with regards to this feature. With respect to varying levels of 'disappointing', personally losing this feature would ruin my ideals of what 2.0 is.

For the meantime, curiosity from not knowing is killing me more than the prospect of not having this feature :smiling_imp:

AdamWillden avatar Jul 11 '16 10:07 AdamWillden

I would be very sad if this doesn't make it into 2.0, but it wouldn't be the end of the world -- I can just keep the Babel step a few more months, e.g. until 2.1 arrives with it. I'll just be glad to have 2.0 finally shipped, cause it brings so much other goodness for which there are no any workarounds that our community (Aurelia Framework) is waiting for. A 2nd step Babel transpilation can still be used to get async/await with a es5 target.

niieani avatar Jul 11 '16 13:07 niieani