For a `expect interface xxx` declaration, I wish i...
# multiplatform
l
For a
expect interface xxx
declaration, I wish it would be allowed to have the implementation as
actual typealias xxx = yyy
, with
yyy
being an (abstract) class. Any good reason why this isn’t allowed? My use case is for example
org.w3c.dom.Node
, which is an abstract class in Kotlin/JS but an interface in Kotlin/JVM. I didn’t find an aesthetical way to bridge the two.
j
Because Kotlin (and JS) doesn't have multiple inheritance, a class implementing the expect interface wouldn't be able to inherit from another class as well as the actual abstract class.
j
Suppress the error. It'll work fine.
It's either ACTUAL_WITHOUT_EXPECT or something else. You basically search part of the error message in the Kotlin repo to find the key to suppress
m
That's good to know. I've run into problem with abstract vs open a lot.
j
Yeah I get it when using value classes in one actual but not the other, or typealiasing to a typealias. There's a lot of things that don't work but actually do when you suppress
l
Many many thanks for the tip: using @Suppress(“ACTUAL_WITHOUT_EXPECT”) did the trick. Amazing that one can trick Kotlin into supporting multiple inheritance 🙂
j
Well, it'd only be multiple inheritance if the class that implemented the expect interface also inherited from another class, in which case in Kotlin/JS it would be inheriting the actual typealias abstract class as well. As long as you're not inheriting anything else it's fine.