Without the interface, I get the string property a...
# javascript
a
Without the interface, I get the string property as "string". Anyway around this or do I just have to nix the interface?
t
Unfortunately there is now way ariund it. Feel freee to upvote https://youtrack.jetbrains.com/issue/KT-31876
notice, that you do have the propertu
string
even when you use an interface - but it will be available through the protype only. so
myDataClass.string
will work in js, too
s
Not sure if this would meet your needs as a work around, but for json object creation from a data class or just straight the below work, albeit not very pretty.
Copy code
interface MyInterface {
    var string: String
}

@Serializable
data class MyDataClass(
    override var string: String
) : MyInterface


fun main() {

    val json = Json(JsonConfiguration.Stable)
    val test = JSON.parse<MyDataClass>(
        json.stringify(MyDataClass.serializer(), MyDataClass("Hello World!")
        )
    )
    println(JSON.stringify(test))  // {"string":"Hello World!"}

    val test2 = jsObject<MyInterface> {
        string = "Hello World2!"
    }

    println(JSON.stringify(test2))  // {"string":"Hello World2!"}

}