Hello, I am generating the definition for my libr...
# javascript
t
Hello, I am generating the definition for my library, but I release that the dependencies from maven are not included. For instance, I get this kind of return type in my
d.ts
file:
Copy code
kotlinx.coroutines.flow.SharedFlow<kotlin.collections.List<string>>
I currently use
Copy code
sourceSets {
        all {
            languageSettings.useExperimentalAnnotation("kotlinx.serialization.ExperimentalSerializationApi")
        }

        val commonMain by getting {
            dependencies {
                implementation("org.jetbrains.kotlinx:kotlinx-serialization-protobuf:1.2.2")
                implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.1")
            }
        }
        val commonTest by getting {
            dependencies {
                implementation(kotlin("test"))
            }
        }
        val jsMain by getting
        val jsTest by getting
    }
How can I include the definitions from kotlin stdlib and coroutines?
Sorry to push... Is this possible?
h
Legacy or IR? IR bundles them, legacy does not. What is your usecase?
b
This has nothing to do with Legacy backend (since only IR backend can generate .d.ts files
t
Thanks for getting back at me. It is using IR. We want kotlin.js to be delivered separately so we can cache it.
b
Here are key concepts to understand about .d.ts generation: 1. It only generated declarations for kotlin entities marked with @JsExport 2. If kotlin dependency does have these markers, those will be included and bundled into generated .d.ts file 3. Otherwise, you need to make sure that your public api that's marked with @JsExport only exposes the types that are also marked with @JsExport 4. A quick workaround to expose types from kotlin dependencies that are not marked with @JsExport is to wrap them into a wrapper class that is marked
Copy code
@JsExport
value class MySharedFlow(private val flow: SharedFlow) {
  // expose flow methods here and delegate to backing field
}
t
Also, regarding the typing, we have an historic project, that we want to eventually migrate to Kotlin. We are first trying to move a simple module over kotlin, and re-import it via npm
Copy code
"our-module": "<file://path/to/kotlin/project>"
The issue with the typing is that is exposes some types that are not defined in the
d.ts
such as
kotlinx.coroutines.flow.SharedFlow<kotlin.collections.List<string>>
b
BONUS: you can use npm-publish gradle plugin to help you with bundling and publishing to npm (will help with above issue)
t
Thanks @Big Chungus , I already use your package 😊 I think the solution here would be to do wrappers for some of the types. I was thinking using
api
instead of
implementation
but it does not work, or even use the JS version of
coroutines
but it does not include any typing. Thanks, I'll work with what you gave me
b
Yeah, dependencies themselves have nothing to do with it 😄 Just make sure that anything that's public in your lib (either from your own sources or dependencies) is marked with @JsExport. As simple as that
👍 1