Closed lgrignon closed 4 years ago
I indeed never tried to compile this class with version 2.x.
Fixed with https://github.com/cincheo/jsweet/commit/5c4d5afcba0a8f5657ed086d8e17682fa4c1bc98
But remains a bug, I opened another issue for it: https://github.com/cincheo/jsweet/issues/558
558 is fixed. There is still one bug to be fixed: https://github.com/cincheo/jsweet/issues/559
But we will face a second issue that I think would be difficult to fix:
Your Iterable<T> conditional(..)
method returns an Iterable<T>
, which will transpiles to Array<T>
but the new Iterable<T>() {}
anonymous class which is returned won't actually transpile to an array in javascript (it will transpile to a new instance of a generated class matching this anonymous iterable prototype).
It would be nice to support those iterable/iterators with ES6+ generators, but it would require a non trivial amount of work.
I can certainly find a workaround by rewriting this class. However, I am confused that you closed #559 with some code committed. Did you finally found a solution or is this just the indication that you are not going to dig it further?
No, #559 is indeed fixed. There was a regression in equals management with generic types
It is maybe my mistake as I am not (yet) completely fluent with the JSweet build environment, but when I try to compile my class I get:
org/jsweet/examples/iterable/Iterables.ts(9,20): error TS2322: Type 'Iterables$1<T>' is not assignable to type 'T[]'. type 'Iterables$1<T>' is not assignable to type 'T[]' at /Users/luc/java/jsweet-examples/src/main/java/org/jsweet/examples/iterable/Iterables.java(7) Property 'length' is missing in type 'Iterables$1<T>'.
Happy to investigate further if the problem is likely to be on my side!
Oh, the remaining error is actually the one with the Iterable vs Array. I don't think there will be an easy fix so I recommend writing the code slightly differently if possible
All clear now! Many thanks for all the hard work ;-)
Seems that just converting the anonymous Iterable to an inner class is doing the trick... at least in term of getting a valid TS file as output :-)
You are welcome. Please keep me updated about wether it finally worked. Cheers
Trying to transpile the example from this comment: https://github.com/cincheo/jsweet/issues/519#issuecomment-569721715
will cause an error due to nested generic anonymous classes