Edoardo Luppi
02/19/2024, 5:15 PMinterface One {
prop: BaseType
}
interface Two extends One {
prop: RefinedType // extends BaseType
}
Artem Kobzar
02/19/2024, 6:23 PMexternal open class BaseType
external class RefinedType : BaseType
external interface One {
val prop: BaseType
}
external interface Two : One {
override val prop: RefinedType
}
Doest the direct option work?Edoardo Luppi
02/19/2024, 6:26 PMval
, and not when prop is var
, which is the most common caseEdoardo Luppi
02/19/2024, 6:27 PMexternal open class BaseType
external class RefinedType : BaseType
external interface One {
var prop: BaseType
}
external interface Two : One {
override var prop: RefinedType
}
Edoardo Luppi
02/19/2024, 6:30 PMJsPlainObject
could be able to do 👀 just an hintArtem Kobzar
02/19/2024, 6:33 PMArtem Kobzar
02/19/2024, 6:33 PMEdoardo Luppi
02/19/2024, 6:35 PMval
and a custom inline set* method that write to the underlying property?
But would methods work with the new plain objects?Artem Kobzar
02/19/2024, 6:36 PMArtem Kobzar
02/19/2024, 6:38 PM@JsPlainObject
external interface One {
val prop: BaseType
}
@JsPlainObject
external interface Two : One {
override val prop: RefinedType
}
One(BaseType()) // works
One(RefinedType()) // works
Two(RefinedType()) // works
Two(BaseType()) // Compile-time error
Two(RefinedType()).apply { prop = RefinedType() /* Compile-time error, because you can't mutate the property */ }
Two(RefinedType()).copy(prop = NewRefinedType()) // works
Edoardo Luppi
02/19/2024, 6:39 PMexternal interface One {
var prop: BaseType
}
external interface Two : One {
override var prop: RefinedType
}
to
external interface One {
val prop: BaseType
open inline fun setProp(p: BaseType): Unit = asDynamic().prop = p
}
external interface Two : One {
override val prop: RefinedType
override inline fun setProp(p: RefinedType): Unit = asDynamic().prop = p
}
Edoardo Luppi
02/19/2024, 6:40 PMEdoardo Luppi
02/19/2024, 6:40 PMEdoardo Luppi
02/19/2024, 6:41 PMEdoardo Luppi
02/19/2024, 6:44 PMEdoardo Luppi
02/19/2024, 7:00 PMval modified = Two(RefinedType()).modify(prop = NewRefinedType())
At this point I'm just throwing ideas around lolturansky
02/19/2024, 11:00 PMvar
has no big sense.
In wrappers we plan to use val
for JSO-interfaces even if in TS it's declared as mutable property.
P.S. Props - open questionturansky
02/20/2024, 9:02 AMvar
in data classes and use readonly JSO in TS.
Both have fine copy methods/syntax.
cc @Sergei GrishchenkoEdoardo Luppi
02/20/2024, 9:07 AMval
is usually better.
But, I'd like to have a way to mutate the object without performing a copy of it every time. See example I made aboveturansky
02/20/2024, 9:22 AMvar
for your properties.
Additional bonus - inheritance problems :)Edoardo Luppi
02/20/2024, 9:28 AMturansky
02/20/2024, 9:29 AMvar