I'm writing type defs and came across ```{GridCoor...
# javascript
b
I'm writing type defs and came across
Copy code
{GridCoordinates2D|HexagonalGridCube2D|Point} HexagonalGridCoordinates2D
and wondered, if there was a way to model that in Kotlin. Couldn't you use a marker interface for that? As in: an empty interface that all of these types extend?
1
e
Is that a union type? If it is, there is no direct translation. You can play with overloads if it's a parameter, or have - as you suggested - a sealed interface with multiple extenders. But then you still need a way to discriminate.
t
If it’s union - pill depends on use case.
b
union type yes; just found out that finding a common super class is probably impossible
t
Why?
b
used in multiple ways; but overload is going to work, thank you
t
If overloads work - you are lucky!
It’s simplest use case 😉
b
property still probably needs to be Any
but that's better for type safety than passing the wrong stuff to the constructor