How to compile Kotlin into TypeScript?

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


I wrote a plugin for gradle to assist with kotlin - typescript integration. It basically generates the .d.ts files for you.

Issues discussed here https://medium.com/@dr.david.h.akehurst/building-applications-with-kotlin-and-typescript-8a165e76252c

Gradle plugin is available in the gradle plugin registry.