Extending a Nested Struct in TypeScript

Is there a way to extend a nested struct? My naive solution throws an error:

import * as S from '@effect/schema/Schema'

const A = S.struct({
  foo: S.struct({
    bar: S.string,
  }),
})

// Now I want to add a "baz" prop to "foo"
// The below throws a runtime error: "Error: Duplicate property signature foo"
const B = A.pipe(
  S.extend(
    S.struct({
      foo: S.struct({
        baz: S.string,
      }),
    }),
  ),
)
Was this page helpful?