Marc Knaup
11/18/2020, 3:25 PMSomeExternalInterface.someFun()
? 🤔
This actually compiles and works. this
will be null
in SomeDslClass.Companion.foo
which is okay because it’s not actually used.
It allows for a nice DSL with zero overhead for unused Kotlin interface types and companion classes.
external interface SomeDslClass {
@Suppress("NESTED_CLASS_IN_EXTERNAL_INTERFACE")
companion object
}
fun SomeDslClass.Companion.foo() {
console.log("it works!")
}
fun main() {
SomeDslClass.foo()
}
turansky
11/18/2020, 7:07 PMCompanion
- legal solution, which already used by Kotlin/JS browser classesMarc Knaup
11/18/2020, 7:08 PMturansky
11/18/2020, 7:11 PMMarc Knaup
11/18/2020, 7:12 PMCompanion
.turansky
11/18/2020, 7:12 PMMarc Knaup
11/18/2020, 7:13 PMturansky
11/18/2020, 7:15 PMexternal interface X {
companion {
inline fun foo() {
println("It works!")
}
}
}
Marc Knaup
11/18/2020, 7:15 PMinline
is a good idea. I’d just have to add an additional function to hide away internal/private API which is blocking internal 🤔Marc Knaup
11/18/2020, 7:16 PMMarc Knaup
11/18/2020, 7:17 PMval
without getter in some of my Companions. That won’t work.turansky
11/18/2020, 7:17 PMturansky
11/18/2020, 7:18 PMinline
turansky
11/18/2020, 7:19 PM@Suppress
- https://youtrack.jetbrains.com/issue/KT-42871turansky
11/18/2020, 7:19 PMMarc Knaup
11/18/2020, 7:20 PMturansky
11/18/2020, 9:00 PMMarc Knaup
11/18/2020, 9:01 PMturansky
11/18/2020, 9:14 PMMarc Knaup
11/18/2020, 9:40 PM