java2typescript icon indicating copy to clipboard operation
java2typescript copied to clipboard

Java package name components that are JavaScript reserved words cause failures

Open JessHolle opened this issue 1 year ago • 3 comments

If one has a Java package name like "com.acme.delete" or "com.acme.export" then the resulting TypeScript will not work due to "delete" and "export" being reserved words.

JessHolle avatar Jun 29 '23 14:06 JessHolle

Hi @JessHolle sorry for late in answer, but I missed your request.

A solution could be add a prefix like $ to the reserved words. What do you think ? you still need this fix ?

bsorrentino avatar Jun 23 '24 14:06 bsorrentino

I ended up using java2typescript as an inspiration for my own custom Javadoc-doclet-based TypeScript definition generator -- and generating only a .d.ts file, i.e. no actual JavaScript implementation.

On this particular front, I ended up using xx_yy_zz namespaces for packages, rather than x.y.z namespaces to resolve the issue.

Trying to straddle Java and JavaScript's notions of some types (i.e. chars and strings) in the same way that Nashorn does was challenging and the result a bit imperfect, I believe. And some of Nashorn's special sugar for extension (extend, etc), didn't end up getting covered quite correctly, IIRC.

JessHolle avatar Jun 24 '24 11:06 JessHolle

P.S. I only generate a .d.ts file in my case because I'm dealing with a very large Java API -- and don't want to produce large amounts of actual JavaScript due to that.

JessHolle avatar Jun 24 '24 11:06 JessHolle