gpt4 book ai didi

javascript - Kotlin JavaScript 到 TypeScript 定义文件

转载 作者:IT老高 更新时间:2023-10-28 13:26:52 29 4
gpt4 key购买 nike

我找到了ts2kt library这将从任意 .d.ts 文件创建 Kotlin 头文件。但是,我想往相反的方向走。

我想构建一个可以编译为 JavaScript 的 Kotlin 库,但我想从 TypeScript 中使用它。有没有办法让 Kotlin 生成一个 .d.ts 来自其公开接口(interface)的文件?我是否以正确的方式处理这个问题?

最佳答案

In Kotlin 1.4-M1 support for exporting TypeScript definitions was added

Preview: TypeScript definitions

Another feature in the new Kotlin/JS IR compiler we’re excited to show off is the generation of TypeScript definitions from Kotlincode. These definitions can be used by JavaScript tools and IDEs whenworking on hybrid apps to provide autocompletion, support staticanalyzers, and make it easier to include Kotlin code in JS and TSprojects.

For top-level declarations marked with @JsExport (see above) in a project configured to use produceExecutable(), a .d.ts file with theTypeScript definitions will be generated. For the snippet above, theylook like this:

// [...]
namespace blogpost {
class KotlinGreeter {
constructor(who: string)
greet(): string
}
function farewell(who: string): string
}
// [...]

In Kotlin 1.4-M1, these declarations can be found in build/js/packages/<package_name>/kotlin alongside the corresponding,un-webpacked JavaScript code. Please note that since this is only apreview, they are not added to the distributions folder by default fornow. You can expect this behavior to change in the future.

关于javascript - Kotlin JavaScript 到 TypeScript 定义文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42537677/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com