but no options available to to unsafe cast `json {...
# javascript
e
but no options available to to unsafe cast
json {"key1":"value1", "key2":"value2", "key3":"value3" }
into a Kotlin type.
r
this wouldn’t be “casting” in a Kotlin JS context persay, and it might be useful to understand how Kotlin objects look from a JS perspective in order to understand why
when Kotlin compiles to JS, it uses different names for generated members than the plain strings you see in your Kotlin code (unless you’re using the @JsName annotations)
so force-casting the JS object to be treated like the Kotlin object wouldn’t actually work the way you’d expect - Kotlin code would look for the generated name, and wouldn’t find the member
depending on what you’re trying to do, there are a lot of good alternatives. One of which is using the Kotlin serialization library to translate between “dynamic” types and Kotlin types
with Kotlin serialization, you could probably even just parse the dynamic object into a Map<String, Boolean> and get solid results
t
Described json is
Record
in Kotlin
Wrapper already exists
Record<String, String>
is what you need
👍 1
e
good stuff, thank you both!
🎉 2