Handling Constructor Defaults with Nested Schema Classes in Effect Typescript

Is this something else I am missing when using constructor defaults with nested Schema classes, I want to be able to create like const b = new B({}) but not need the property signature and Schema.withConstructorDefault(() => new A())

Could the schema classes make method and constructor parameter types be changed to accept the nested optional shape? Is that even possible?

import * as Schema from "effect/Schema"

class A extends Schema.Class<A>("A")({
  a: Schema.String
    .pipe(Schema.propertySignature)
    .pipe(Schema.withConstructorDefault(() => "Effect Schema!"))
}) {}

class B extends Schema.Class<B>("B")({
  a: A
}) {}

class C extends Schema.Class<C>("C")({
  a: A
    .pipe(Schema.propertySignature)
    .pipe(Schema.withConstructorDefault(() => new A()))
}) {}

// Expected
const a = new A({})

// Type Error :(
const b = new B({})

// Works :)
const c = new C({})
Was this page helpful?