I have found the ts2kt library which will create Kotlin header files from arbitrary .d.ts
files. But, I want to go in the opposite direction.
我找到了ts2kt库,它将从任意.d.ts文件创建Kotlin头文件。但是,我想走向相反的方向。
I want to build a Kotlin library that will compile to JavaScript, but I want to use it from TypeScript. Is there a way to make Kotlin generate a .d.ts
file(s) from its exposed interfaces? Am I approaching this the right way?
我想构建一个可以编译为JavaScript的Kotlin库,但是我想从TypeScript中使用它。有没有办法让Kotlin从其公开的接口生成.d.ts文件?我是以正确的方式接近这个吗?
1 个解决方案
#1
1
I'm looking to do something like this to share models between Android and JS. There is the ts-generator library, which takes jvm classes and generates ts definitions from them.
我希望做这样的事情来分享Android和JS之间的模型。有一个ts-generator库,它接受jvm类并从中生成ts定义。
I haven't tried this yet, but it theoretically should work. Separate the API for your library (or an interface the api implements) into a kotlin common module. You can then compile the api into a jvm module, and run it through the ts-generator to generate ts definitions.
我还没有尝试过这个,但理论上应该可行。将库的API(或api实现的接口)分离为kotlin通用模块。然后,您可以将api编译为jvm模块,并通过ts-generator运行它以生成ts定义。
Maybe there is a clever way to do this to skip the compilation to jvm for ts definition generation.
也许有一种聪明的方法来跳过编译到jvm以进行ts定义生成。
#1
1
I'm looking to do something like this to share models between Android and JS. There is the ts-generator library, which takes jvm classes and generates ts definitions from them.
我希望做这样的事情来分享Android和JS之间的模型。有一个ts-generator库,它接受jvm类并从中生成ts定义。
I haven't tried this yet, but it theoretically should work. Separate the API for your library (or an interface the api implements) into a kotlin common module. You can then compile the api into a jvm module, and run it through the ts-generator to generate ts definitions.
我还没有尝试过这个,但理论上应该可行。将库的API(或api实现的接口)分离为kotlin通用模块。然后,您可以将api编译为jvm模块,并通过ts-generator运行它以生成ts定义。
Maybe there is a clever way to do this to skip the compilation to jvm for ts definition generation.
也许有一种聪明的方法来跳过编译到jvm以进行ts定义生成。