https://kotlinlang.org logo
#multiplatform
Title
# multiplatform
g

Grantas33

05/24/2020, 5:45 PM
Is there a way to use @JsExport annotations (or other annotations, specific to its own platform) in common code?
👀 1
j

Justin

05/24/2020, 5:47 PM
If you figure this out (I’m told it is possible using version 1.4-M2 of Kotlin and the js plugin), I’d love to see what your build.gradle.kts looks like. I’m hoping to use that patterns to auto generate typescript defs for my nodeJs library target.
👍 1
r

Robert Jaros

05/24/2020, 5:51 PM
You can declare an annotation with
expect
and declare
actual typealias
in platform code.
But I had problems using Java annotations with parameters this way.
r

russhwolf

05/24/2020, 5:55 PM
If the annotation has parameters then you need `expect`/`actual` for them as well. It’s doable, but it’s a bit of a pain because you can’t make use of
@OptionalExpectation
For
@JsExport
in particular, it’s coming in 1.4-M2 and tracked here https://youtrack.jetbrains.com/issue/KT-35966
👍 1
r

Robert Jaros

05/24/2020, 6:37 PM
I've just tested the `expect`/`actual` for annotations with parameters and something had to be fixed in Kotlin in the last six months, because it works fine for me now. Even with
@OptionalExpectation
.
That's great - I can use spring data annotations in common code now.
7 Views