-
Notifications
You must be signed in to change notification settings - Fork 9
Using KustomExport types from external JS back in Kotlin #33
Description
Hi! First, just wanted to say thanks for this library. It's made the TypeScript from Kotlin so much nicer to use. :)
I ran into an issue while using with external and have been looking into a fix but I'm fairly new to Kotlin so I could just be doing something wrong. I'm using the latest on the master branch as well as tried with 0.8.0 of KustomExport.
If I have a type exported from Kotlin with @KustomExport (e.g. class Item), create that type in JS (e.g. new Item()), and then send it back through Kotlin, accessing the properties from that object returns undefined.
I have this example Kotlin:
@KustomExport
class Item(
val id: Long,
val name: String
)
@KustomExport
class KotlinLibrary(private val js: JsLibrary) {
fun getItem(): Item {
return js.getItem()
}
}
external class JsLibrary {
fun getItem(): Item = definedExternally
}and this JS:
export default class JsLibrary {
getItem(): Item {
return new Item(1, "Test")
}
}
// ---
const js = new JsLibrary()
const kt = new KotlinLibrary(js)
const item = kt.getItem()
console.log(item.name) // undefined but should be "Test"I've been attempting to add support for this use case but thought I'd open an issue just in case you are already familiar with this use case or know a way to support it. I've written a test for the use case here. The first four assertions pass but the others that interface with KustomExport do not pass.
It appears that returning an instance from JS, when it's ran through CommonItem.exportItem(), the getters that proxy to the internal common are no longer connected. I'm new to Kotlin though so that could be incorrect.
Thank you for your time!