Hi, I'm using Kotlin 1.9.22 Multiplatform and I've...
# javascript
q
Hi, I'm using Kotlin 1.9.22 Multiplatform and I've enabled
generateTypeScriptDefinitions
on a node library I'm creating. I see that the namespace in Typescript is generated from the package name of the definition file. Is there any way to override it? For example, the code:
Copy code
package a.b.c

@JsExport
fun doSomething(param: String) { ... }
generates
Copy code
export declare namespace a.b.c {
    function doSomething(param: string)
}
while I would like
Copy code
export declare namespace Helpers {
    function doSomething(param: string)
}
a
Hey, as far as I know, there is no api for such a transformation
e
This is something that comes up now and then here in Slack, and also at work. I have people on the TS side asking me "why are you using this complex nesting?", and so I explain to them how the Kotlin side works. But the questions we should ask are: 1. Can a compiler plugin change the qualified name of types/functions? 2. If yes, would that mess up the d.ts generation?
The JVM target has a
@JvmPackageName
annotation, might be worth looking at how it works
And correct me if I'm wrong, but I guess ESM + per-file granularity + per-file d.ts would solve the namespacing issue for
useEsModules()
b
I use single work package names for all exported code, so if you do
package Helpers
you'll get what you want
Java people will probably want to kill you, but ...
e
https://youtrack.jetbrains.com/issue/KT-65127 This is what they're doing for Swift export. So basically they're using the module's name as qualifier.