https://kotlinlang.org logo
Title
s

Sebastian

07/06/2022, 9:21 AM
Hey peeps! After upgrading Kotlin from 1.6.10 to 1.6.21 recently, our exported TypeScript definitions are broken for some cases. It’s mostly about Kotlin generating nested comments inside method signatures, e.g.
/* kotlin.collections.List<any/* com.company.manager.data.ApiAnswer */> */
). The inner comment closing statement (
*/
) will make the outer comment closing appear as regular code and thus generate a syntax error in TypeScript. I’ll put a slightly more complete example in the thread. Did anyone have any issues like that, or is there any related entry in the issue tracker? I haven’t found anything so far, but can’t imagine that I’m the only one with totally broken TypeScript definitions. 🤔
Shortened example: Kotlin class:
@JsExport
@ExperimentalJsExport
public class Manager(
  private var proxyKey: String,
  private var countryAlpha2: String,
) {
  public companion object {
    public fun build(proxyKey: ProxyKey, countryAlpha2: String): Manager =
      Manager(proxyKey.name, countryAlpha2)
  }

  public fun currentAnswers(): List<ApiAnswer> {
    return someSerializer.convertResponseToApiAnswers(response)
  }
}
Generated Typescript definition (
manager.d.ts
):
export namespace com.company.manager {
    class Manager {
        constructor(proxyKey: string, countryAlpha2: string);
        static get Companion(): {
            build(proxyKey: any/* com.company.manager.common.ProxyKey */, countryAlpha2: string): com.company.manager.Manager;
        };
        currentAnswers(): any/* kotlin.collections.List<any/* com.company.manager.data.ApiAnswer */> */;
    }
}
→ The nested comments inside the method signature of
currentAnswers()
are not valid TypeScript syntax and break everything that comes after the
*/>
.
Ok, looks like this was actually fixed in Kotlin 1.7.0. https://github.com/JetBrains/kotlin/commit/5223efd3f1d94e745adc7884bbc50ce47a1cbb68 I’ve updated my issue in the issue tracker.