Hi, I trying move project to IR, but I have issue ...
# javascript
m
Hi, I trying move project to IR, but I have issue with 'reflection'
Copy code
internal actual fun Any.getFieldValue(fieldName: String): Any? {
    val thisDynamic: dynamic = this
    return thisDynamic[fieldName]
}
this works well on LEGACY, but on IR it return undefined. I try to play with that and
thisDynamic[fieldName+"_1"]
return right value, but I don't think this is safe solution. This is any class, where I want to find value by string. Is there any idea how to do it in IR?
r
You can't. You need to think about alternative solutions for your use case. E.g. you can use kotlinx.serialization to serialize your kotlin object to json and then access json fields by string name.
­čĹŹ 1
m
Yes, I trying find alternative solution, but why it work for legacy, but not for IR?
r
The internal representation of kotlin objects has changed. Check: https://youtrack.jetbrains.com/issue/KT-44944/KJS-Non-mangled-types