I’m trying to write a library using the new Kotlin/JS IR compiler. Specifically, I want to write the library using Kotlin, but to publish it as a NPM package to be used in a Typescript/Node project.
I have a NPM dependency in the project defined which already has TS types defined and a readily available.
To allow the library to work smoothly together with using it in tandem with this dependency in a project it would make sense to use the already defined TS types when available.
As an example, I want to define a function in my library foo(message: Message)
where Message
is actually a type coming from the NPM dependency.
What I hoped to be able to achieve would be an output where the generated types in my compiled output contained something like this:
import * as someDep from 'some-dependency'
export namespace foo.bar.baz {
function foo(message: someDep.Message): void;
}
However, I haven’t been able to get this done. Instead, the Message is simply just there as an undefined type, meaning the d.ts
file is essentially broken.
For an example of a simple project which tries to do what I’m asking about see: GitHub - jsfr/sample-kotlin-js
Here I create a simple abstract class named Consumer
which should be able to take a Message
type from the external google-protobuf
NPM library. However, in the resulting d.ts
file the Message is present with no definition of itself.
Is what I’m trying to do here possible or is there some other approach I should take instead? This seems like an important thing to be able to do for good interoperability.