I'm trying to export a class with an array, someth...
# multiplatform
m
I'm trying to export a class with an array, something like this
class Foo<T>(val array: Array<T>)
but when I annotate with
@JsExport
I get the warning saying Array is not exportable, but the docs seem to suggest otherwise. error:
Exported declaration uses non-exportable property type: Array<T>
docs: https://kotlinlang.org/docs/js-to-kotlin-interop.html#kotlin-types-in-javascript
g
I think it maybe the
T
that is not exportable in your case.
m
ah, shoot, are generics still not exportable?
g
Yes but not fully... Afaik Generics from Kotlin are way more powerful than Generics in iOS or Typescript (with the current export at least), and from memory the current export doesn't apply generics bounds on typescript for example... so it may be confusing (we've considered them and eventually remove them from our code). I'll consider using them in the API (classes exported with @JsExport) when Kotlin will generate directly Swift/Typescript code, but's that's my personal opinion.
m
in my case the generics have no bounds, this is just a container, have you had success exporting anything generic like this?
g
In IDE I see a warning when a generic is used in a method parameter for example. And if I extends a Kotlin abstract class from Typescript, the Kotlin
is
does not work for some reasons...
So in a way, it is working, Typescript is able to call a Kotlin method on a generic class with a generic parameter, but the expected behavior of
is
(or related methods) can be tricky / different from the other stacks (like Android / iOS)
m
hmm, in my case I only have methods returning specific things like
fun getAll(): MyCollection<Person>
so I should be okay, as long as typescript can "follow" the generic to typecheck it
I don't intend to export any function that is itself generic
g
You don't have a
get(index: Int): T
kind of methods on your collection? It may be good enough for you then.
m
this is a very weird "collection" but it makes sense for my case. the most it has is
Copy code
class Collection<T>(val items: Array<T>)
and I want js code to do things like
getAll().items[0]
for example
👍 1