Vampire
08/19/2020, 3:02 AMinline fun <reified T> options(options: T.() -> Unit): T = object : T {}.apply(options)
?serebit
08/19/2020, 3:07 AMT
is open or abstract, or even that it has a no-argument constructor, so creating an anonymous object from it is out. Also, even if you could, generic types aren't constructable that way. I can't give you an effective way to work around this that doesn't take advantage of reflection, but maybe someone else can.Vampire
08/19/2020, 3:11 AMval result = ncc(input, object : NccOptions {
override var sourceMap: Boolean? = true
override var license: String? = "LICENSES"
}).await()
I changed it to
val result = ncc(input, object : NccOptions {}.apply {
sourceMap = true
license = "LICENSES"
}).await()
Now I thought it could be made like
val result = ncc(input, options<NccOptions> {
sourceMap = true
license = "LICENSES"
}).await()
with such a method, but it will probably not work even with inline reified typesVampire
08/19/2020, 3:14 AMjsObject
is for and even nicer
val result = ncc(input, jsObject {
sourceMap = true
license = "LICENSES"
}).await()
I somehow thought this would not be typesafe but it is