how do I map a structured type to an anonymous obj...
# javascript
j
how do I map a structured type to an anonymous object?
b
kotlin object expression doesn’t work for you?
Copy code
val alarmInfo = object {
  val whenMillis = 0.0
  val delayInMinutes = 0.0
  val periodInMinutes = 0.0
}
j
I'm mapping a native API and wanted a proper type for the method parameter type
Using a real class and not worrying about an anonymous object is probably the right thing here
b
Well, I think using external declarations is the best way to map native API.
Mangling isn't applied to external declarations
Anyway, you can use
JsName
to get proper name
j
The external API doesn't have an object which corresponds to this parameter. It just documents it as "an object with keys named a, b, c". So I wanted a way to represent that as a proper class with constructor and val properties in Kotlin code but have it turn into a
{a:.., b:.., c:..}
declaration on the JS side
b
So, it can be external interface
external interface exists only on compile time
j
that's what I ended up doing, but the caller still has to create an instance somehow. I used a factory function whose name matched the interface type name to act like a constructor, but it's basically pure boilerplate: https://kotlinlang.slack.com/archives/C0B8L3U69/p1515166470000015
b
Yes, we going to improve it, see https://youtrack.jetbrains.com/issue/KT-21653
j
Looking forward to it. Thanks!