Skip to content

Commit

Permalink
Convert union possibilities to refs when generating types.
Browse files Browse the repository at this point in the history
  • Loading branch information
mrdziuban committed Oct 23, 2024
1 parent 535e8df commit 96ac052
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/main/scala/scalats/TsGenerator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,13 @@ final class TsGenerator(
union.possibilities match {
case Nil => sys.error(s"Can't generate TS code for union `${union.typeName}` with 0 members")
case h :: Nil => generateType(h)
case l @ (_ :: _) => imports.iotsUnionC("[" |+| l.toList.intercalateMap(imports.lift(", "))(generateType) |+| "]")
case l @ (_ :: _) =>
imports.iotsUnionC("[" |+|
l.map {
case TsModel.Interface(typeName, _, typeArgs, _) => TsModel.InterfaceRef(typeName, typeArgs)
case TsModel.Object(typeName, _, _) => TsModel.ObjectRef(typeName)
}.intercalateMap(imports.lift(", "))(generateType) |+|
"]")
}

/** Produces value code for a scala `enum`/`sealed trait`/`sealed class` */
Expand Down

0 comments on commit 96ac052

Please sign in to comment.