I've been debugging for quite a while now; turns o...
# javascript
b
I've been debugging for quite a while now; turns out there is a distinction between a JS object literal and a JS class for certain APIs (class properties get minified!); Handlebars for instance only works when you pass an object literal; is there a way to specify that in the type signature?
1
e
No, there is no way to create a "plain" object in non-external code. Follow and upvote https://youtrack.jetbrains.com/issue/KT-56618
Also https://youtrack.jetbrains.com/issue/KT-17683 to prefer proper fields instead of getters.
b
I found that I can use @JsPlainObject with an external modifier to fix it, but I can not require this in the type signature
maybe Record<String, Any>?
e
What do you mean with
but I can not require this in the type signature
b
e.g. imagine a template function like: renderTemplate('path/to/template.hbs', {key: 'test', 'key2': 1})
the second parameter is an object literal with the template context
typing the function like:
Copy code
external fun renderTemplate(path: String, context: Any)
breaks when a class is passed as the context parameter
reason for that is that class attributes are minified
so instead of passing {'key': 'test'}, you get {'s_1': 'test'}
e
Yeah, if the type is as generic as
Any
or
dynamic
, there is no way to limit to plain objects.
Record
might work, but it will limit the type of data you can pass too much imo
b
yeah, I think in this case Record is fine
can't require a record of records though, right?
would need to be a recursive type def
kinda like: Record String | Int
maybe using a map for that API works as well, thank you so far
not minifying attributes would also be great
e
KT-17683 would solve your issue btw.
b
already voted for it, thank you 🙂
✔️ 1
@JsField could solve it but you're still left with the type safety issue