Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

[BridgeJS] Support union types

Open
#663 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
35/100
Issue type
Feature
Clarity
Needs clarification
Activity status
Quiet
Domain
api

Research direction

No file or test is named. Start by locating the existing rawvalue support referenced in the issue and reviewing how the shown TypeScript unions map to Swift; clarify how runtime changes between variants should be represented. Done means the Example union and example() signature interoperate correctly, including dynamic changes between Foo and Bar.

Written by the indexing model from the issue text.

Description

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.

Dominant language
Swift
Stars
986
Forks
76
Avg merge
21h 11m
Merged PRs (30d)
4

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from swiftwasm/JavaScriptKit

All issues in swiftwasm/JavaScriptKit

Similar issues

More Swift issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.