Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compile from Kotlin to JS with type definitions #1

Open
MartinEden opened this issue Apr 19, 2017 · 3 comments
Open

Compile from Kotlin to JS with type definitions #1

MartinEden opened this issue Apr 19, 2017 · 3 comments

Comments

@MartinEden
Copy link

First let me say this isn't a problem I'm expecting the maintainer of this repository to fix. I just thought they might be in a good position to comment on what's possible.

I have a Kotlin library I want to use on the JVM and in TypeScript. Using the official Kotlin2JS compiler, I can compile my code to JS. But then I don't get type definitions. And using this library I can generate type definitions, but not the actual implementation.

Is there a good way of combining the two? Do you know if JetBrains plan to provide type definition generation as part of their Kotlin2JS compiler?

@ntrrgc
Copy link
Owner

ntrrgc commented Apr 19, 2017

Hi.

I've not yet tried Kotlin2JS, so I don't know much about how it works, but as long as the generated JS API generated is consistent with the original Kotlin API of your program, it should pose no special inconvenience.

This project was created to handle data types, so it has some important limitations with regard to generating definitions for libraries or applications (as opposed to just exporting some data types):

First, definitions for methods are not created. This is far from impossible though. Just take a look at how definitions for properties are created and you'll find it should not be very different from that.

Second, applications and libraries need to split their classes in packages, which are often nested. These can be mirrored with TypeScript namespaces, but currently ts-generator does not support them: it just generates a single flat definition file.

These limitations can be overcome although in practice bridging languages is rarely seamless, as every little impedance mismatch between the two needs to be worked around.

I would actually prefer if Kotlin2JS generated the definition files itself as an additional compilation artifact instead of using this library for that. Since they already have a compiler, they have all the needed type information at build time. This library on the other hand has to recreate that same information using reflection once the application is running (even if normally this means only some modules are imported without doing much). As far as I know there are no plans to support TypeScript definition generation in Kotlin2JS though...

@dupski
Copy link

dupski commented Aug 15, 2018

Yep, this definitely feels like something that Kotlin2JS should be doing itself. Typescript is pretty ubiquitous these days :)

@NikolayMetchev
Copy link

When will we see this feature is unclear but it is filed in the issue tracker:
https://youtrack.jetbrains.com/issue/KT-16604

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants