Want to make sure my assumptions are correct, firs...
# javascript
s
Want to make sure my assumptions are correct, first time working with Kotiln JS target &
dynamic
types: I have a js function from an imported library which returns
dynamic
. I'm trying to cast the return type's properties to kotlin types to create a typesafe wrapper of sorts. I can cast js primitives to kotlin primitives fine, but anything more complex like a js
Uint8Array
as
UByteArray
give me a
ClassCastException
. Wondering what the strategy is for this? Do I need to create my own
Uint8Array
type & implementations?
b
For these kind of casts use .unsafeCast<YourType>() function. But be absolutely sure that the type you are casting to is correct
1
This basically skips all runtime checks and just assumes desired type.
s
Ah, didn't see that function. Thanks! I'm as sure as I can get with javascript 🙂
t
You can use
is
and
as
operator with
Uint8Array
- no limits
1