[K/JS] Create JavaScript Simple Object plugin that helps create typed JS objects

This commit is contained in:
Artem Kobzar
2024-01-10 16:30:02 +00:00
committed by Space Team
parent 45b8f99107
commit 300702a7e7
46 changed files with 1841 additions and 2 deletions
+21
View File
@@ -0,0 +1,21 @@
package foo
import kotlinx.jso.JsSimpleObject
@JsSimpleObject
external interface User {
var name: String
val age: Int
}
fun box(): String {
val user = User(name = "Name", age = 10)
if (user.name != "Name") return "Fail: problem with `name` property"
if (user.age != 10) return "Fail: problem with `age` property"
val json = js("JSON.stringify(user)")
if (json != "{\"age\":10,\"name\":\"Name\"}") return "Fail: got the next json: $json"
return "OK"
}