Hello all! If I want to extend a external class wi...
# javascript
t
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
Type already known, no cast required:
Copy code
inline fun Blob.stream(): Promise<ReadableStream> =     asDynamic().stream().unsafeCast<Promise<ReadableStream>>()
Extension - most Kotlinish solution
t
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!
t
👍 1