It would be great to have union types just for ext...
# language-proposals
a
It would be great to have union types just for external declarations in K/JS, so it's a lot easier to create typings for a TypeScript library. I think it would be a pretty easy task to implement it just in that specific context so this is why I post a message specifically for this
d
It won't be easy, because it means full support of union types in type system, which is main blocker from design and implementation sides
a
Ah, but doesn't they exist in a way when using multiple return types in a
when
?
d
No.
when
expressions are nothing more than
select
function from inference point of view
Copy code
when {
  ... -> x
  ... -> y
  ... -> z
}
// same as
fun <K> select(vararg value: K): K

select(x, y, z)
a
Then what happens there ? 🤔
d
Boolean & String
is an intersection type, not union
Copy code
interface A
interface B
interface C : A, B
interface D : A, B

fun test(c: C, d: D) {
    val x = select(c, d)
    // type of x is CommonSuperType(C, D) = A & B
}
a
Ah okay I see, thanks for the information :)