Effect CommunityEC
Effect Community2y ago
5 replies
timsuchanek

Defining Back Relations with Effect Schema

How to define back relations aka circular dependencies with Effect Schema? Here's an example:
import * as S from '@effect/schema/Schema'

const Post = S.struct({
  title: S.string,
  content: S.string,
  comments: S.array(S.suspend(() => Comment)),
})

const Comment = S.struct({
  content: S.string,
  post: S.suspend(() => Post),
})

As mentioned in the docs, I'm using suspend. I also tried a few options like S.suspend around Comment or Post itself, but I get the following type error from TypeScript
image.png
Was this page helpful?