https://kotlinlang.org logo
#javascript
Title
# javascript
e

Edoardo Luppi

09/21/2023, 11:44 AM
Couldn't find any, is there a YouTrack issue for K/JS to get an annotation similar to
@JvmStatic
?
👍 1
a

andylamax

09/21/2023, 1:49 PM
I don't think that there is any
gratitude thank you 1
a

Artem Kobzar

09/22/2023, 7:49 AM
No, unfortunately
e

Edoardo Luppi

09/22/2023, 8:04 AM
@Artem Kobzar thanks! Do you think it would be a valid feature request? Example I've got on hands right now:
Copy code
public class Properties private constructor(private val data: Map<String, String>) {
  public companion object {
    @JvmStatic
    fun decode(string: String): Properties {
       ...
    }
  }
}
Will output the following
d.ts
:
Copy code
class Properties {
    private constructor();
    static get Companion(): {
        decode(string: string): Properties;
    };
}
I can see two problems from a JS/TS consumer point of view: 1. What's a "companion"? 2. Why can't I simply
Properties.decode(...)
To workaround the companion issue I'm now using
Copy code
@JsName("factory")
public companion object Factory {
So it will look good in all platforms, and a JS/TS consumer can use:
Copy code
Properties.factory().decode(...)
a

Artem Kobzar

09/22/2023, 11:26 AM
I was thinking about it and I think it's a valid feature request for sure
gratitude thank you 1
e

Edoardo Luppi

09/22/2023, 11:34 AM
Well apparently there was an issue, see https://youtrack.jetbrains.com/issue/KT-18891
The comments seems to be asking for a similar implementation
2 Views