Skip to content

[BridgeJS] Support union types #663

Description

@Amzd

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions