Effect CommunityEC
Effect Community3y ago
21 replies
spaethnl

Issues with Recursive Schemas and Class Interface

I'd like to get feedback on recursive schemas with the class interface.
This doesn't work:
class ItemBase extends S.Class({
  value: S.number,
  children: S.array(S.lazy(() => Item.schema()))
}) {}

Because Property 'schema' does not exist on 'typeof Item'.

Attempting (Item as any), and then passing the type to lazy like this:
class Item2 extends S.Class({
  value: S.number,
  children: S.array(S.lazy<Item2>(() => (Item2 as any).schema()))
}) {}

Results in: 'Item2' is referenced directly or indirectly in its own base expression.

Ignoring the error with // @ts-ignore ruins type inference.
Was this page helpful?