Effect CommunityEC
Effect Community2y ago
19 replies
Emberoshi

Decoding Specific Field with Schema.Struct

Hey guys, Using a Schema.Struct how can I decode a specificy field? Like this example
const createFieldCodec =
  <Fields extends Schema.Struct.Fields>(s: Schema.Struct<Fields>) => (key: keyof Fields) =>
    Schema.decodeSync(s.fields[key]);

const Person = Schema.Struct({
  name: Schema.optional(Schema.String)
});

const nameCodec = createFieldCodec(Person)("name")
Was this page helpful?