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

István Mészáros

11/25/2023, 10:01 AM
👋 Hi everyone! 🙂 In our first KMP (JS) project we're just experimenting everything and tried to enable ES6 classes via:
Copy code
tasks.withType<KotlinJsCompile>().configureEach {
    kotlinOptions {
        useEsClasses = true
    }
}
In the generated typescript definitions we see:
Copy code
static fromString(value: string, $box: Nullable<BigDecimal>): BigDecimal;
The corresponding Kotlin source is:
Copy code
@JsName("fromString")
    actual constructor(value: String) : this(BigNumber(value), scaleOf(value))
Why the argument
$box
is added to the generated TS code? It's not there if ES6 classes are disabled. We use Kotlin
1.9.21
Thanks in advance!
👀 2
a

Artem Kobzar

11/27/2023, 11:41 AM
Hey. Could you share please the code that you annotated with the JsExport annotation. It could be added inside inner classes constructors.
i

István Mészáros

11/27/2023, 12:17 PM
Hi Artem! I created a repo to demonstrate the issue: https://github.com/imeszaros/box-issue I also pushed the dist directory to see what output I got: https://github.com/imeszaros/box-issue/blob/master/build/dist/js/productionLibrary/box-issue.d.ts I hope this helps! Thaks a lot for your effort!
e

Edoardo Luppi

11/27/2023, 12:44 PM
That's some neat way of declaring static methods without a companion, it seems. I'm not sure that use case was ever intended to be applicable.
If it indeed wasn't, I like it! But maybe proper support for statics would be better.
3 Views