swiftwasm / swiftwasm/JavaScriptKit
[BridgeJS] Support union types
Nobody has claimed this yet.
- Dominant language
- Swift
- Stars
- 986
- Forks
- 76
- Avg merge
- 21h 11m
- Merged PRs (30d)
- 4
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
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.
Assessment
- Tech stack
- javascript, swift, typescript
- Domain
- api
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100