Skip to content

js.| union type #1824

@sjrd

Description

@sjrd

Edit: the original proposal was to name it \/.

It would be worth thinking about a union type constructor for facade types. Similar to js.UndefOr[+A] in its construction, js.|[+A, +B], or whatever it's called, would represent a value of type A or B. It would have zero API, though. The basic idea is the following:

@RawJSType // don't do this at home
sealed trait |[+A, +B]

object | {
  implicit def fromA[A](a: A): A | Nothing = a.asInstanceOf[A | Nothing]
  implicit def fromB[B](b: B): Nothing | B = b.asInstanceOf[Nothing | B]
}

Then of course we need ways to transitively convert an A, a B, or a C to an A | B | C. This probably needs a bit of recursive implicit magic. Even trickier: convert A | B, A | C and B | C to A | B | C ^^

Metadata

Metadata

Assignees

Labels

enhancementFeature request (that does not concern language semantics, see "language")

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions