working on a multiplatform library which is also s...
# arrow
s
working on a multiplatform library which is also supposed to be used with K/Js, I'm getting
[NON_EXPORTABLE_TYPE] Exported declaration uses non-exportable return type: 'arrow.core.Either<A, B>'
when I add
@JsExport
to a class containing an Either. same for
NonEmptyList
. Is there any possible solution to this?
a
maybe we should add
@JsExport
to every class in
arrow-core
?
s
@Serializable
as well while you're at it 😅
regarding the JsExport issue, I have no idea what was going on there. even my domain error interfaces caused uncaught type errors in js, while being annotated with
@JsExport
. I merged the back and frontend repos and directly import the modules now instead of a maven library and this fixes it
a
serialization support for kotlinx.serialization is provided in an additional artifact
arrow-core-serialization
s
yeah I saw that but for returning
Either
I needed to wrap it into a serializable class itself
a
it should be enough to add the corresponding module to your kotlinx.serialization configuration
s
it's about the kotlin rpc library, the code is being generated, not sure if I have access to a config for that. but I need to revisit this again
a
if you have any more information so I can try to reproduce it, that would be great
s
will look into it! (need to clean up after merging the repos first)
alright so it was indeed the module missing, and you still need the UseSerializers annotation.
Copy code
cbor {
    serializersModule = SerializersModule {
        contextual(Either::class) { (a, b) -> EitherSerializer(a, b) }
        contextual(Ior::class) { (a, b) -> IorSerializer(a, b) }
        contextual(NonEmptyList::class) { (t) -> NonEmptyListSerializer(t) }
        contextual(NonEmptySet::class) { (t) -> NonEmptySetSerializer(t) }
        //  contextual(Option::class) { (t) -> OptionSerializer<*>(t) }
    }
}
...
@file:UseSerializers(
    NonEmptyListSerializer::class,
    EitherSerializer::class,
    OptionSerializer::class,
    UuidSerializer::class
)
I couldn't find the Arrow module from this PR though https://github.com/arrow-kt/arrow/pull/3413
a
it's going to be released as part of 2.0
s
ah okay. but what about the OptionSerializer? IJ says it can't infer the type
a
it should work similarly to
Either
and
Ior
, (I see you wrote
OptionSerializer<*>
there)
s
Argument type mismatch: actual type is 'kotlinx. serialization. KSerializer<CapturedType(*)>', but 'kotlinx. serialization. KSerializer<T>' was expected.
for the
t
parameter in
Copy code
contextual(Option::class) { (t) -> OptionSerializer(t) }
s
yeah. in the provider argument it is <*> but it works for all the others
Copy code
public override fun <T : Any> contextual(
        kClass: KClass<T>,
        provider: (typeArgumentsSerializers: List<KSerializer<*>>) -> KSerializer<*>
    ): Unit = registerSerializer(kClass, ContextualProvider.WithTypeArguments(provider))