Issues with Implementing Pipeable in Nested Classes

I've been having a go at adding Pipeable to a class and having issues when the class is nesting. Have simplified it down a bit:
interface Box extends Pipeable {
  readonly content: Content
}

// Need this to be able to nest the Box definition, since i get a type error for the pipe method
const _Box = Schema.suspend(
  (): Schema.Schema<{ content: Content }> =>
    Schema.Struct({
      content: Content
    })
)

// Contents of a box.
const Content = Schema.Union(
  Schema.TaggedStruct("Blank", {}),
  Schema.TaggedStruct("Text", { text: Schema.String }),
  Schema.TaggedStruct("Row", {
    boxes: Schema.Array(_Box)
  }),
  Schema.TaggedStruct("Col", {
    boxes: Schema.Array(_Box)
  }),
  Schema.TaggedStruct("SubBox", {
    box: _Box
  })
)
type Content = typeof Content.Type

// Need this to inject the `pipeArgument` into
const make = (b: {
  content: Content
}): Box => {
  const box = {
    ...b
  } as Box

  box.pipe = function() {
    return pipeArguments(this, arguments)
  }

  return box
}

const Box = Schema.Struct({
  content: Content
})

// A @1x1@ box containing a single character.
// char :: Char -> Box
const char = (c: string): Box =>
  make({
    content: { _tag: "Text", text: c[0] ?? " " }
  })

const foo = char("A")
const bar = foo.pipe((a) => a.content._tag)

Can find the full code here or a playground here

I've not found too much documentation on how to implement Pipeable, but looking at the docs for printer/Doc and the type definition makes my head hurt. 🤯 Any help would be appreciated 🙏
Was this page helpful?