|
|
|
|
|
by nielsbot
143 days ago
|
|
I guess I just want to be able to do something like this in Swift: let x: String | Int
switch x {
case let value as String:
// handle String value here
case let value as Int:
// handle Int value here
}
There's one more thing about TypeScript-style union types: string literals. I think it's great to be able to do type Options = "option_1" | "option_2" ... "option_n"
And subsequently I could use let t: Options
switch t {
case "option_1":
// handle `"option_1"` case here
...
case "option_n":
// handle `"option_n"` case here
}
I think this is more programmer friendly than requiring an out-of-line definition of a new `enum`. Sometimes you just want to write some code, you know? |
|