Help with Recursive Schema Migration in Effect

Greetings All! I am new to Effect, and currently struggling to migrate my Zod schema to effect/schema. I do have the following 2 recursive schemas:

import { Schema as S } from "effect";
import { BaseEntitySchema } from "@/common";
import { FieldsSchema } from "./fields";
import {
  schema as customerSchema,
  Schema as CustomerSchema,
} from "../customer";

export const schema = S.partial(S.extend(BaseEntitySchema, FieldsSchema));

export const Schema = S.extend(
  schema,
  S.Struct({
    // $customer1: S.suspend(() => CustomerSchema),
    $customer2: S.suspend(() => customerSchema),
  }),
);



import { BaseEntitySchema } from "@/common";
import { Schema as S } from "effect";
import { FieldsSchema } from "./fields";
import {
  Schema as ContractSchema,
  schema as contractSchema,
} from "../contract";

export const schema = S.partial(S.extend(BaseEntitySchema, FieldsSchema));

export const Schema = S.extend(
  schema,
  S.Struct({
    // $contracts1: S.Array(S.suspend(() => ContractSchema)),
    $contracts2: S.Array(S.suspend(() => contractSchema)),
  }),
);


Commented lines with $customer1 and $contracts1 show TS error, andI can't make the recursion work with S.suspend().

Any ideas appreciated. Ignore FieldsSchema and BaseEntitySchema they contain bunch of unrelated fields.
Was this page helpful?