Is it possible to compile Kotlin to Typescript?
# javascript
p
Is it possible to compile Kotlin to Typescript?
k
No, it's impossible
Why do you need it?
p
There are established tools/workflows and documentation for typescript + angular/react/vuejs. I like kotlin but figure it would be easier to transpile the few DTO's and validation logic
n
i wouldn’t say it’s impossible i would say it’s not implemented and probably never will be by jetbrains but you can do it with some effort 🙂
k
@pabl0rg TypeScript is a transpiler which produces JavaScript, right? So if you get JavaScript anyway, why should it matter whether intermediate TypeScript pass runs or not?
g
@konsoletyper The issue is with things like decorators, the way Typescript compiles decorators down to js is not the same as how Kotlin compiles annotations to js, in fact annotations dont work at all for Kotlin-js compiler right now. Having an intermediate step where a kotlin compiles everything to js like normal but then outputs a typescript file with a typescript decorator and then let typescript do its thing would be nice. Then kotlin could be used with angular2+
But there's still ways around it, like with code generation that we spoke about the other day
k
So, what you really need is support of decorators
p
When working on an angular2+ project, would decorators be enough to get auto-complete/ide help for the javascript generated by kotlinJS?
k
Why do you need auto-completion for JavaScript? You can get auto-completion for Kotlin source code
p
is there anywhere i can learn how to use kotlin with angular2?
Sorry to have troubled you. I just thought of the TS target as a way to share kotlin backend code with a frontend project that uses react/angular2/vue in a way that is documented, deals with css, and is learnable/usable by an average developer like me.
k
There is request to generates TS headers, and it's of course implementable. We surely will generate TS headers eventually, though it's not in 1.2 roadmap
But for now you can easily write react application with Kotlin
g
@pabl0rg you can use it with Angular2 but you will need to look at how the Angular 2 decorators are compiled down to Javascript. Instead of using decorators you'll to attach that data to the class manually. Also, if you're planning to use the AOT compiler you will probably run into trouble