Challenges in Creating Discriminated Unions with Schema Classes

Is it possible to creat a discriminated union of Schema classes? In the docs, the example given is with Structs:
const Circle = Schema.Struct({ radius: Schema.Number })
const Square = Schema.Struct({ sideLength: Schema.Number })
const DiscriminatedShape = Schema.Union(
  Circle.pipe(Schema.attachPropertySignature("kind", "circle")),
  Square.pipe(Schema.attachPropertySignature("kind", "square"))
)

And it doesn't seem to work with Classes, i.e.
class Circle extends Schema.Class<Circle>('Circle')({ radius: Schema.Number })  {}
class Square extends Schema.Class<Square>('Square')({ sideLength: Schema.Number })  {}
const DiscriminatedShape = Schema.Union(
  Circle.pipe(Schema.attachPropertySignature("kind", "circle")),
  Square.pipe(Schema.attachPropertySignature("kind", "square"))
)

The resulting TS error being:
Property '[TypeId]' is missing in type 'Circle' but required in type 'Variance<Circle, { readonly radius: number; }, never>'.


I feel like I'm missing a fundamental difference between Schema.Struct and the result of extending
Schema.Class
.
Was this page helpful?