Looking at @JsPlainObject, is there a way to defin...
# javascript
b
Looking at @JsPlainObject, is there a way to define a tuple?
1
b
Could you explain what you mean by defining a tuple?
e
A tuple is just a facade over a JS array. You don't need
@JsPlainObject
for that. https://github.com/JetBrains/kotlin-wrappers/blob/master/kotlin-js/src/jsMain/kotlin/js/array/JsTuple.kt
b
I'd like something like
Copy code
@JsPlainObject
external interface WhenPredicate {
    val `when`: JsTuple2<Predicate, String> 
}
(Predicate is a plain object as well)
e
But how do you expect to use it? Given that example and kotlin-wrappers
JsTuple2
you'd end up with something like
Copy code
val wp = WhenPredicate(tupleOf(..., "something"))
b
it's an interface for a JS object that I access
the object looks like {"when":[{"eq":[1, 2]}, "2"]}
in typescript I'm using a tuple
e
Copy code
{
  "when": [
    {
      "eq": [
        1,
        2
      ]
    },
    "2"
  ]
}
Would translate to exactly what you posted in Kotlin
b
ok, thanks, I was mainly worried about the compiler plugin
e
accessing the two indexes is done using destructuring
Copy code
val (p, s) = whenPredicate.when
b
I've run into so many limitations along the way and file too many bugs for this plugin 🙂
e
Yeah it's definitely not completely polished, but it looks like we're getting there. I still believe in KT-17683 tho as a way to transfer plain objects between Kotlin and JS. It looks like they somewhat overlap in functionality.
b
I'm following that issue as well
e
The distinction is the
external
part, so in your case external + JPO annotation is the way to go, as you're indeed importing an external library and you don't want a real JS
class
to end up in your bundle.