Hello all! If I want to extend a external class with some es6+ apis, what is the proper way to do that?
I tried to do an extension function (although I know that doesn't really makes sense) like
Copy code
external fun Blob.stream(): Promise<ReadableStream>
But the compiler told me that's illegal. Intellij suggested I change it to
Copy code
@Suppress("NOTHING_TO_INLINE")
inline fun Blob.stream(): Promise<ReadableStream> = asDynamic().stream() as Promise<ReadableStream>
which I think will work for me, but I was wondering if anyone knows of a better way to do this?
t
turansky
09/28/2021, 4:01 PM
Type already known, no cast required:
Copy code
inline fun Blob.stream(): Promise<ReadableStream> = asDynamic().stream().unsafeCast<Promise<ReadableStream>>()
turansky
09/28/2021, 4:02 PM
Extension - most Kotlinish solution
t
Todd
09/28/2021, 6:01 PM
Interesting. Extension functions feel more like an implementation then defining an external interface so I felt like there might be something else (without redefining the whole clas). But this works! Thanks!