Edoardo Luppi
12/17/2024, 9:30 PM// commonMain
public expect class ZByteArray(size: Int)
// jsMain
public actual typealias ZByteArray = Uint8Array
However, with the new types it is required to specify a generic parameter
// jsMain
public actual typealias ZByteArray = Uint8Array<ArrayBufferLike>
Which then doesn't compile anymore.
The ZByteArray
typealias is then used in exported classes/interfaces. For example
@JsExport
public interface ZOutputStream {
public fun writeBytes(bytes: ZByteArray)
}
and that means subclassing Uint8Array<ArrayBufferLike>
isn't a solution.
Note that while the kotlin-wrappers way emulates TypeScript, TypeScript also uses a default generic type, which isn't possible in Kotlin.
interface Uint8Array<TArrayBuffer extends ArrayBufferLike = ArrayBufferLike>
turansky
12/17/2024, 10:09 PM// jsMain
@JsName("Uint8Array")
public actual open external class ZByteArray(size: Int) : Uint8Array<ArrayBufferLike>
?turansky
12/17/2024, 10:10 PMEdoardo Luppi
12/17/2024, 10:19 PMpublic actual open external class ZByteArray
this version is then incompatible with other kotlin-wrappers types like Buffer
sealed external class Buffer : Uint8Array<ArrayBufferLike>
Edoardo Luppi
12/17/2024, 10:37 PMunsafeCast<Buffer>
and unsafeCast<ZByteArray>
. Not ideal but it's a first step.turansky
12/18/2024, 1:49 AMEdoardo Luppi
12/18/2024, 9:05 AM@JsExport
signatures that use the value class?Edoardo Luppi
12/18/2024, 11:07 AM@JsName("Uint8Array")
external class UUint8Array : Uint8Array<ArrayBufferLike>
Than UUint8Array
could replace all usages of Uint8Array<ArrayBufferLike>
to mimic the default generic type.turansky
12/18/2024, 11:53 AMturansky
12/18/2024, 12:19 PMEdoardo Luppi
12/18/2024, 12:21 PMunsafeCast
. Since typed arrays are also used under kotlin-nodes types, every interaction with them requires an unsafeCast
.