quiro
06/12/2024, 8:18 AMsealed interface
but if I add the external
modifier then it doesn't enforce strict typing. What I'd like is:
sealed interface Element
external interface Object : Element {
val properties: Record<String, Element>
}
external interface Primitive {
val type: Type
val value: Any?
}
external interface Array : Element {
val items: Array<Element>
}
// TS
const obj: Element = { properties : { items: { type: Type.string, value: 'something' } } }
But it doesn't work because Element
is not external. If I make Element
external though, then it is compatible with {}
Edoardo Luppi
06/12/2024, 10:03 AMprop: Union<One, Two>
The assignment can be checked so that
val one = One()
prop = one // ok
prop = "wrong" // error
val two = Two()
prop = two // ok
turansky
06/12/2024, 1:40 PMElement
as union in TS, because it's sealed
quiro
06/12/2024, 1:41 PMsealed
to be incompatible with external
quiro
06/12/2024, 1:42 PMsealed interface
not to match an object that doesn't belong to any of the implementationsturansky
06/12/2024, 1:43 PMturansky
06/12/2024, 1:45 PMturansky
06/12/2024, 1:46 PMquiro
06/12/2024, 2:00 PMEdoardo Luppi
06/12/2024, 2:06 PM{}
is perfectly valid for TS perspective.
How would you solve it?quiro
06/12/2024, 2:09 PMEdoardo Luppi
06/12/2024, 2:11 PMEdoardo Luppi
06/12/2024, 2:15 PMquiro
06/12/2024, 2:19 PMsealed interface Element
external interface Object : Element {
val properties: Record<String, Element>
}
external interface Primitive {
val type: Type
val value: Any?
}
external interface Array : Element {
val items: Array<Element>
}
what I assumed would be produced is something like:
interface Array {
val items: Element[]
}
interface Object {
val properties: Record<string, Element>
}
type Element = Array | Object
This would enforce the sealing, so that I can't pass in an empty object as a valid instance of the type Element
Edoardo Luppi
06/12/2024, 2:22 PMturansky
06/12/2024, 2:51 PMquiro
06/12/2024, 3:00 PM