:wave: Hi all, I'm trying to generate a TS interfa...
# javascript
q
👋 Hi all, I'm trying to generate a TS interface from Kotlin code. What I would like to achieve is something like:
Copy code
interface Cat {
  name: string
}
but as far as I can see, whenever I generate an interface an additional
__doNotUseOrImplementIt
is added to it. Is there any way to work around this limitation? All I want is for consumers to be able to call a function
sayHello(cat: Cat)
easily from TypeScript (eg
sayHello({ name: 'George' })
a
Only if you will use an external interface. TS and Kotlin interfaces are absolutely different kind of declarations. For now, we haven't found a nice way to implement a Kotlin interface from JS/TS, because Kotlin could be an argument of
is
checks (so, we need to add meta information), they can have default implementations of methods/accessors, and they are nominal (if two interfaces have the same members, they are not equal) in the same time TS interfaces don't exist in runtime at all and have structural typing (if two interfaces have the same members they are equal)
So, the only solution is to use external interfaces for such situations
q
got it, thanks @Artem Kobzar
e
@Artem Kobzar I don't recall anymore, is
@JsExport
supported only for
external interface
, or also for
external class
?
a
As far as remember, only for interfaces
✔️ 1
e
Mmm, would be nice to understand if it's an hard limit, or if it can be relaxed. Re-exporting external classes might be useful I think.
Ahh well, a class might come from a different package, so I don't think it would play well.
q
@Artem Kobzar looks like external interfaces are not supported in common modules, is that expected? I'm getting an error saying
Modifier 'external' is not applicable to 'class'
for the following code:
Copy code
external interface A {
    val something: String
}
a
It's true. We were thinking of adding this ability via an annotation (like @JsExternal), but the discussion was stopped, and I don't know what the current status is. It would be great if you created an issue on YT with your use-case.
e