◐ Shell
clean mode source ↗

[BridgeJS] Support union types

Union types (other than rawvalue which are already done) should be supported. The best way to do this is unclear to me so this issue functions as a discussion point.

Example:

export type Foo = { foo: string } 
export type Bar = { bar: string }
export type Example = Foo | Bar
export function example(): Example

Could maybe generate:

@JSClass struct Foo {
    @JSGetter var foo: String
    @JSSetter func setFoo(_ value: String) throws(JSException)
}
@JSClass struct Bar {
    @JSGetter var bar: String
    @JSSetter func setBar(_ value: String) throws(JSException)
}
@JSClass enum Example {
    case foo(Foo)
    case bar(Bar)
}
@JSFunction func example() throws(JSException) -> Example

Note that ts unions can change dynamically eg if I set foo to null and bar to a string, the type changes from Foo to Bar, so idk if that works with an enum like this in Swift.