Effect CommunityEC
Effect Community3y ago
6 replies
Charles

Issues with S.lazy for Recursive Types and S.optionFromNullable

Hi, I have some issues to use S.lazy for Recursive types:
typescript   interface Bed {
    name: string
    room: O.Option<Room>
  }

  const Bed: S.Schema<Bed> = S.lazy(() =>
    S.struct({
      name: S.string,
      room: S.optionFromNullable(Room)
    })
  )
  // type Bed = S.To<typeof Bed>
  interface Room {
    name: string
    beds: readonly Bed[]
  }

  const Room: S.Schema<Room> = S.lazy(() =>
    S.struct({
      name: S.string,
      beds: S.array(Bed)
    })
  )
  // type Room = S.To<typeof Room> 
, I have this error on Bed : Types of property 'room' are incompatible. Type 'Room | null' is not assignable to type 'Option<Room>'. Type 'null' is not assignable to type 'Option<Room>' Thanks !
Was this page helpful?