<@U02BK8ABTQF> something I've noticed over time is...
# javascript
e
@Artem Kobzar something I've noticed over time is people tend to
@JsExport
data classes, as effectively they're just convenient in Kotlin. What you end with is a TS declaration with:
Copy code
copy(positional args)
toString()
hashCode()
equals(other)
•
copy
makes little sense imo as it is not ergonomic to use, not one bit •
toString
good •
hashCode
dubious about its usefulness in JS/TS •
equals
good My 2c is
copy
and
hashCode
make little sense in being exported, at least by default. Looking for feedback here. I'm curious about other people's opinion.
a
Oh, a great question. I remember at some point we've decided not to export
componentN
functions, so maybe we can think about those as well. I also remember one of the nice suggestions to export a TS-friendly overload for
copy
, so it will accept an anonymous JS-object (since
copy
is powerful as a combination of default arguments and named parameters features). So, it could be look like this:
Copy code
// Kotlin

@JsExport
data class User(val name: String, val age: Int)
Copy code
// TypeScript

const user = new User("George", 23);

const copy = user.copy({ age: 24 });
Regarding the
hashCode
also true, but I just afraid that there is a small group of people who needs such a feature (I just need to understand if there is and their use case)
👀 1
c
Since
equals
and
hashCode
have a very similar contract, I think it would be strange to export one and not the other, even if they are not necessarily useful
➕ 1
+1 for the
copy({ age: 24 })
export, that seems useful and idiomatic
e
I think, especially for data classes, more customization would be nice. Then we start with a limited default, and allow exporting additional data class methods. We already have
@JsExport.Default
and
@JsExport.Ignore
, what about something like
@JsExport.DataClass(copy = false, hashCode = false, ...)
. Now, the name is bad. But I guess you get where I want to go.
👍 1
However, I also think that if
copy
ends up being more ergonomic, then maybe all of this can be avoided. But again, customization is always nice to have.
a
The issue with the annotation approach is that we want to move away from it for the sake of building tool configuration (since, yes, you can design your API more precisely, but with dependency declarations, you can't). It doesn't mean we're going to drop the annotation, but the preferred way to export would be the SwiftExport-like DSL.
e
It doesn't mean we're going to drop the annotation
You got me worried for a second here ahahaha The entire premise of the annotation is granular control, but I see that using a build DSL is better when you want export patterns/wildcards. Hopefully the two will coexist. But yes, I see the problem.
pepenotingfast 1
a
I think
toString()
export can also be ommited. Typescript tends to assume every object has a toString method, so no need to add it in the definitions
➕ 3
e
That's true, I agree for
toString
.