I have a question regarding a Kotlin JS snippet. I...
# javascript
j
I have a question regarding a Kotlin JS snippet. It look like my nullable variables become undefined when being used inside my component
Copy code
data class FirebaseUser(
    val email: String,
    val uid: String,
    val accessToken: String,
)

@JsModule("@jlengrand/firebase-ports")
@JsNonModule
external object FirebasePorts{
    fun logIn() : Promise<FirebaseUser>
}                

var user : FirebaseUser? by mutableStateOf(null)

Button(attrs = {
                    onClick {
                        console.log(JSON.stringify(user))                        
                        console.log(user)
                        console.log(user!!.uid)
                    }
                }) {
When doing this, ths results are as following :
Copy code
{"accessToken":"exampleToken","email":"<mailto:example@gmail.com|example@gmail.com>","uid":"example"}
{accessToken:exampleToken,email:example@gmail.com,uid:example}
undefined
Is that expected, and how do I fix this? I mean, the value is there clearly
t
Copy code
external interface FirebaseUser {
    val email: String
    val uid: String
    val accessToken: String
}
j
Annnnd bingo
Ok, ty ^^. Lots of bad habits from Backend kotlin to erase I see. Cheers!
b
FYI, JSON.stringify should not be used with any non-external kotlin type
The behaviour of doing so is very unpredictable
t
With ES6 and private properties (in perfect future Kotlin/JS) it must be very predictable and transparent 🙂 cc @Sergei Grishchenko
🤞🏽 1
🤞 5