is there a way to compile to named parameters in j...
# javascript
b
is there a way to compile to named parameters in js instead of positional parameters? bigger data classes are kinda unfun to use from JS since you need to do new Data(1, 2) instead of new Data({month: 1, day: 2})
✅ 1
➕ 1
a
There is no way to do it automatically at this point, but I really think about adding such an option. From your perspective, it's more useful as a global configuration for all the functions/constructors or via an annotation for more granular design of the JS API?
b
definitely annotation based I think
some classes with only 1 or 2 parameters would need to pass an object as well otherwise
I'm currently prototyping a shared API client for TS and the JVM and I have to write quite some glue code around everything to make it feel like idiomatic JS
🙏 1
without that feature, I need to write mapping code that translates @JsPlainObject annotated interfaces into data classes for instance
👍 1
a
The ticket to track the updates to the feature: https://youtrack.jetbrains.com/issue/KT-63669/
b
thank you
another pain point to a certain degree is the conversion between JsMap and KtMap, but that has utility methods at least
a
This part is also in the scope of re-work
b
fantastic, thank you so much
e
Totally in favor of this approach. Looks perfect for exported data classes.
I believe it should be an opt-in behavior tho. Either we relegate it to data classes by default, or normal classes should opt-in. Named parameters are not always the right approach, especially for functions that accept one or two parameters.
I need to write mapping code that translates @JsPlainObject annotated interfaces into data classes for instance
I do the same for two reasons: 1. aforementioned issue 2. the fact we do not have
@JsField
, so properties are not serializable