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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With