Multiple Types

Well, TypeScript has the magic that I think I need, namely recursive union types (formulation "recursive union types" by me):

type Result = number | string | Result[]

function processResult(result: Result) {
    if (Array.isArray(result)) {
        result.forEach((item) => {
            processResult(item)
        })
    }
    else if (typeof result === "number") {
        console.log("number " + result)
    }
    else if (typeof result === "string") {
       console.log("string " + result)
    }
}

processResult([1, "hello"]) // prints "number 1" and "string hello"
processResult([1, true]) // error: Type 'boolean' is not assignable to type 'Result'.

...but of course I want to have switch (as for enums) and not if ... else ... in Swift. So a union type for me is like an enum with associated values, but without the ceremony (and allowing recursive definitions).