Can you use the `where` keyword with typealias? If so, how?

I just learned that Kotlin supports generic intersection types with the where keyword as in:

interface TwoPhase
interface Ac120V

fun <T> foo(ac: T) where T : TwoPhase, T: Ac120V {
    // do stuff...

Now I’m wondering if you can make a typealias for an intersection (or union) type? I don’t know. I expected to be able to do something like:

typealias Not3Phase = <T> where T : TwoPhase, T: Ac120V


typealias Not3Phase = TwoPhase & Ac120V

If there’s a way to do this, it’s not obvious to me.

1 Like

I think I figured this out. The answer is “No” and the reason is because that’s what Interfaces do. The correct syntax (works today) is:

interface Not3Phase : TwoPhase, Ac120V

I waited for you to find this out for yourself :wink:

Just kidding. I assumed it, but I couldn’t answer, because the union / intersection miscommunication confused me.