Effect CommunityEC
Effect Community2y ago
5 replies
joepjoosten

Extracting "Sub" Schema from Schema

Hi all!

How to get a "sub" schema from a schema that is passed as a parameter of a function?

const TestSchema = S.Struct({
  data: S.Struct({
    a: S.String()
  })
})


function <SCHEMA extends ??Needs to have a S.Struct with a data field??>doSomething(schema: SCHEMA, event: { body: string }) {
  const data = Schema.decodeUnknown(Schema.parseJson(???schema.data???))(event.body)
  ...
}

doSomething(TestSchema, JSON.stringify({ body: {a: 'test'} }))


Is it possible to create a function like 'doSomething', or do i need to define the data field schema, and also pass that schema to the function?
Was this page helpful?