Good day, all. I'm writing an SDK in Kotlin/JS for...
# arrow
a
Good day, all. I'm writing an SDK in Kotlin/JS for an API (Ktor) with lots of common code. Basically a Kotlin Multiplatform project. The SDK is to be consumed by a Typescript project soon. I've run into two issues: 1. I can't seem to use the Either type to represent error/success state in my SDK as I keep getting a warning:
Exported declaration uses non-exportable return type: Either<DomainError, TodoDto>
. I understand that the Either type isn't annotated with
@JsExport
that's why I get the warning. Is there a way to workaround this? 2. How would you recommend I use Arrow's suspending functions in a situation where suspending functions can't be used in a context with the
@JsExport
? Thanks in advance... 🙏🏾
c
Sorry, I don't know about point 1. For point 2, the simplest way is probably to declare helper methods/objects in
jsMain
that return promises. For example, if your common code looks like this:
Copy code
class Foo(
    val a: Int,
) {
    suspend fun foo(): Bar
}
you can create a wrapper for use by JS libraries:
Copy code
@JsName("Foo")
class FooJs internal constructor(
    private val wrapper: Foo,
) {

    constructor(a: Int) : this(Foo(a))

    fun foo() = promise { wrapper.foo() }
}
a
Thank you very much, @CLOVIS. I'll try it out soon. 👍🏾