What's the corresponding of a TS class with static...
# javascript
e
What's the corresponding of a TS class with static methods in Kotlin? Is KotlinJS able to generate those?
c
Seems like you are after Companion Objects:
Copy code
class Foo {
	companion object {
		fun something() : Boolean {
			return true
		}
	}
}
e
@Chris Lee unfortunately this is what gets generated for TS
Copy code
export declare class Foo {
    constructor();
    static get Companion(): {
        something(): boolean;
    };
}
c
Why is that unfortunate? It’s semantically equivalent. You can name the companion object as you like.
e
I would prefer something like
Copy code
export declare class Foo {
    constructor();
    static something(): boolean
}
Which is much more usable from the TS side.
The JVM has
JvmStatic
for this reason, for example.
c
You can’t have both - the Kotlin-generated JS code is designed to work for Kotlin and be interoperable with TS (via Companion object). If you had raw JS it wouldn’t be interoperable with Kotlin. @JvmStatic maintains the Kotlin interop and eases the Java interop, in ways that are specific to the JVM.
j
This would be similar to something like this for Kotlin/Native. Maybe
@JsStatic
for Kotlin/JS.
✔️ 3