Császár Ákos
10/30/2023, 12:21 PMexternal class Window {
fun init(url: String): Promise<MyResponse>
}
class MyResponse{
val message: String? = null
val status: String? = null
}
In the following code, the function call and even the .await() is working, but I think the conversion from json object to MyResponse is not.
val response = window.init("url").await()
console.log("init",response). //logs out as json object instead of MyResponse, and all fields have values.
console.log("message: ", response.message). // will be undefined
Can someone explain me what am I doing wrong?
window.init("url").await().asDynamic().message
works fine, but I want the use the response as a class. Is it possible?Artem Kobzar
10/30/2023, 5:08 PMexternal interface InitResponse {
val message: String?
val status: String?
}
external class Window {
fun init(url: String): Promise<InitResponse>
}
class MyResponse(val message: String?, val status: String?)
fun InitResponse.toMyResponse() = MyResponse(message, status)
And you could use it in your code as:
window.init("url").await().toMyResponse()
Edoardo Luppi
11/01/2023, 1:10 PMexternal interface InitResponse {
val message: String?
val status: String?
}
directly at that point? Without the additional class MyResponse.Artem Kobzar
11/01/2023, 1:18 PMEdoardo Luppi
11/01/2023, 1:44 PMCsászár Ákos
11/03/2023, 10:50 AM