I create alot of non-native JS trait instances as parameters to javascript functions
trait ElementOpts extends js.Object {
val prop1: js.UndefOr[String] = js.undefined
// another 10-15 vals
}
To create an instance:
createElement(new ElementOpts {
override val prop1 = "value1"
override val prop2 = "value2"
// several more, maybe not *all* possible vals
})
However, there is alot typing noise in defining these with the override vals, etc.
It would be nice just to just type a list of key-value pairs and have that turned into the trait which is typechecked so you cannot accidentally add a val that is not defined in the trait:
lit[ElementOpts](prop1="value1",prop2="value2")
and have that turned into the above "new ElementOpts" syntax. I used "lit" to be suggestive of a javascript literal object.
Can scalameta do this? If so, is there an example of something similar? Or should this be handled in a pre-processor of some sort.