I am working on upgrading our kotlin version from ...
# javascript
p
I am working on upgrading our kotlin version from
2.1.20
->
2.2.10
. Previously, we used
KtMap.getInstance().fromJsMap()
to convert a JS Map to a Kotlin map so that the client can send some data back to KM. However, in
2.2.10
getInstance()
is not available anymore. Is there a more preferred way to do these sorts of operators for objects like
KtMap
or
KtList
?
e
Are you compiling to CJS or ESM?
With ESM export, it appears the generated JS code correctly contains a
KtMap.getInstance()
. However the generated TS declarations are incorrect. This might be https://youtrack.jetbrains.com/issue/KT-79926, @Artem Kobzar should be able to confirm.
a
+1 to @Edoardo Luppi There was a bug that inside the d.ts file dropped
getInstance
from the
d.ts
. However, since the 2.3.0 for the
KtMap
and
KtList
the
getInstance
will be dropped and you could use just
KtMap.fromJsMap
from both ESM and CJS (we did it to eliminate differences between the module systems to make the migration smoother)
gratitude thank you 3
p
I appreciate the detailed answers! Good to know that in 2.3.0 there will be a better solution! We are compiling to ESM, for now, I have added an annotation to ignore the TS error
s
@Artem Kobzar can you confirm that the fix will also include
object
types that inherit from sealed interfaces? We have code like this:
Copy code
@JsExport
sealed interface Foo

@JsExport
object Bar : Foo
And the codegen is suffering from a similar problem. We get:
Copy code
export declare interface Foo {
    readonly __doNotUseOrImplementIt: {
        readonly "philo.Foo": unique symbol;
    };
}
export declare abstract class Bar {
    static readonly getInstance: () => typeof Bar.$metadata$.type;
    private constructor();
}
/** @deprecated $metadata$ is used for internal purposes, please don't use it in your code, because it can be removed at any moment */
export declare namespace Bar.$metadata$ {
    abstract class type extends KtSingleton<constructor>() {
        private constructor();
    }
    abstract class constructor implements Foo {
        readonly __doNotUseOrImplementIt: Foo["__doNotUseOrImplementIt"];
        private constructor();
    }
}
The problem is that
getInstance()
is returning the type, not the object itself, so TS complains.
a
s
Realized I never responded here. The bug was mine. 😞
a
@Seth Madison, and thank you so much for filling it out. As a result, we've found a better solution for exporting interfaces with Companion. 🙏
🎉 1
s
Awesome!!