Bernhard
07/28/2026, 7:52 AM@JsExport
@JsPlainObject
external interface Hello: Event<DataHello> {
val greeting: String
}
sealed interface Event<T> {
fun toKt(): T
}
data class DataHello(
val greeting: String
)
@JsExport
fun <T> publish(event: Event<T>) {
val data = event.toKt()
}
right now, I need to do something like this:
suspend fun <T : Any> publish(event: OEEvent): OEClientResponse {
when (event) {
is HelloWorldEvent,
is OtherEventEvent -> {
val result = client.publish(event.toKt())
return result.toJs()
}
else -> throw IllegalArgumentException("Not a supported event")
}
}
is there a better way? I'd like to do something like the attached screenshot where one interface is exported to JS but the other one is kept internal
I'd need a way to create an interface that is only implemented in Kotlin for that type and is not exported to TypeScriptturansky
07/28/2026, 11:53 AMturansky
07/28/2026, 11:54 AMBernhard
07/28/2026, 11:55 AMBernhard
07/28/2026, 11:55 AMBernhard
07/28/2026, 11:56 AMturansky
07/28/2026, 11:56 AMBernhard
07/28/2026, 11:57 AMBernhard
07/28/2026, 11:59 AMturansky
07/28/2026, 12:00 PMturansky
07/28/2026, 12:00 PMturansky
07/28/2026, 12:01 PMBernhard
07/28/2026, 12:01 PMturansky
07/28/2026, 12:02 PMturansky
07/28/2026, 12:03 PMBernhard
07/28/2026, 12:05 PMBernhard
07/28/2026, 12:06 PMBernhard
07/28/2026, 12:07 PMturansky
07/28/2026, 12:07 PMturansky
07/28/2026, 12:07 PMturansky
07/28/2026, 12:08 PMList - JS see Array and so onturansky
07/28/2026, 12:12 PMdata class ABC(
aaa: List<A>,
bbb: Map<String, B>,
ccc: MyEnum,
)
JS see:
interface ABC {
readonly aaa: ReadonlyArray<A>
readonly bbb: Map<string, B>
readonly ccc: "c1" | "c2" | "c3"
}Bernhard
07/28/2026, 12:12 PMturansky
07/28/2026, 12:14 PMBernhard
07/28/2026, 12:15 PMturansky
07/28/2026, 12:15 PMBernhard
07/28/2026, 12:15 PMturansky
07/28/2026, 12:16 PMturansky
07/28/2026, 12:18 PMBernhard
07/28/2026, 12:18 PMBernhard
07/28/2026, 12:54 PM