(Java loves TypeScript :))
d.ts files out of your Java program, so that it is easy to use a JSweet component from TypeScript!
Additionally, with JSweet, it is possible to share Java beans between a Java server and a TypeScript frontend (use the
@Interface(SHARED) annotation on your beans and JSweet will generate the corresponding TypeScript interfaces).
So far so good. But JSweet now strives for even more Java/TypeScript interoperability, by making available two new projects!
The first project is to make available to anyone a web service for translating any TypeScript
d.ts definition file to Java. The beta version of this service is available and you can try it live! All you need to do it to zip your TypeScript
d.ts as explained in the small documentation and you are ready to go. The service will return a zip containing the Java source code of the translated TypeScript API.
import List = java.util.List; import ArrayList = java.util.ArrayList; var l: List
= new ArrayList (); l.add("a");
Besides, the other purpose of J4TS will be to serve transpilers such as JSweet, by having a well-typed runtime for emulating the Java APIs. Having this runtime written in TypeScript is especially interesting for JSweet because it is really easy to package it as a candy, so that JSweet programmers can access the Java APIs in JSweet!
Accessing Java APIs in JSweet gets as simple as declaring a new dependency in your
<dependency> <groupId>org.jsweet.candies</groupId> <artifactId>j4ts</artifactId> <version>0.0.1-SNAPSHOT</version> </dependency>
Then, you can use all the APIs declared/implemented by J4TS and JSweet will magically accept them!
import java.util.List; import java.util.ArrayList; List
l = new ArrayList (); l.add("a");
The beauty of that approach is that the JSweet transpiler compiles against TypeScript APIs
That will be it. I hope that you will enjoy it! Please remember that these two projects are beta and we are hoping for feedback 😉 Note that J4TS will only work with the latest JSweet transpiler snapshot.