Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to compile Kotlin into TypeScript?

I have a JavaScript build in my Kotlin project. How can I produce full TypeScript code instead of JavaScript?

I use Maven; but if you have a Gradle solution, I'm interested.

like image 568
sab Avatar asked Jan 07 '19 21:01

sab


1 Answers

UPDATE: Preview of TypeScript definition generation is available in IR backend since Kotlin 1.4

From Kotlin documentaion:

The Kotlin/JS IR compiler is capable of generating TypeScript definitions from your Kotlin code. These definitions can be used by JavaScript tools and IDEs when working on hybrid apps to provide autocompletion, support static analyzers, and make it easier to include Kotlin code in JavaScript and TypeScript projects. Top-level declarations marked with @JsExport in a project that produces executable files (binaries.executable()) will get a .d.ts file generated, which contains the TypeScript definitions for the exported Kotlin declarations. In Kotlin 1.4, these declarations can be found in build/js/packages/<package_name>/kotlin alongside the corresponding, un-webpacked JavaScript code


Kotlin/JS compiler can't produce TypeScript code. There are no plans to generate full TypeScript code. And there are no third-party solutions as far as I know.

However, we plan to produce TypeScript definition files alongside JavaScript code: KT-16604

like image 84
kzm Avatar answered Sep 29 '22 19:09

kzm