Effect CommunityEC
Effect Community2y ago
26 replies
kondaurovdev

Issue with Recursive Schema Optional Field

Hello, I have a question regarding recursive schemas.

Here's an example. I can't make it work with optional bestFiend.
It works with array of Person like mentioned in documentation

const personFields = {
  name: S.String
}

interface Person extends S.Struct.Type<typeof personFields> {
  // bestFriend?: Person
  friends: ReadonlyArray<Person>
}

const Person: S.Schema<Person> =
  S.Struct({
    ...personFields,
    bestFriend: S.suspend(() => S.optional(Person)),
    friends: S.suspend(() => S.Array(Person))
  })


I get a compiler error
Type 'PropertySignature<"?:", Person | undefined, never, "?:", Person | undefined, never>' is not assignable to type 'Schema<Person | undefined, Person | undefined, never>'.ts(2322)
Was this page helpful?