With K2 and 1.9.20, trying to define an expect class that typealias to a JS
Promise<T>
I encountered https://youtrack.jetbrains.com/issue/KT-21846
Anyone else suppressing this compiler error? I do suppress and it works with the current compiler, but with K2 it just error out.
@anton.bannykh similar, but not the same.
To add context, this is what I'm doing:
Copy code
// Common
public expect class ZDeferred<T>
// JS
@Suppress("ACTUAL_TYPE_ALIAS_TO_CLASS_WITH_DECLARATION_SITE_VARIANCE", "ACTUAL_WITHOUT_EXPECT")
public actual typealias ZDeferred<T> = Promise<T>
// JVM
public actual typealias ZDeferred<T> = CompletableFuture<T>
And usage:
Copy code
// Common
@JsExport
@Suppress("NON_EXPORTABLE_TYPE")
public interface ZSocket {
...
public fun <T : ZSerializable> serialize(serializable: T): ZDeferred<T>
a
anton.bannykh
08/07/2023, 3:36 PM
Could you please create a youtrack issue and describe your use-case? Current K2 restrictions around actualization do break some use-cases involving Promise and having more of them should help to make it more flexible. thank you color
e
Edoardo Luppi
08/07/2023, 3:38 PM
@anton.bannykh will do!
I want to emphasize that currently it works fine (non-K2). I did comment on that issue asking if K2 is going to support it or not, because a lot of code is going to be written around it and I don't want to have to spend a week for fixing it, somehow.
👍 2
Edoardo Luppi
08/07/2023, 3:39 PM
In short, using a typealias allows exposing the platform async API directly, without having to wrap it in additional objects.