Effect CommunityEC
Effect Community2mo ago
2 replies
mpellegrini

Using Pick/Omit with Opaque Classes in Effect Typescript

When using Schema.Stucut it's easy to create new Structs using Pick/Omit. However what would be the best way to Pick/Omit if using opaque Classes instead of Structs?

What I have came up with is the following

https://effect.website/play#713c7cb2f8e0

import { Schema, Struct } from "effect"

export class Task extends Schema.Class<Task>("Task")({
  id: Schema.String,
  done: Schema.Boolean,
  name: Schema.NonEmptyTrimmedString
}) {}

class TaskOmittingDone extends Schema.Class<TaskOmittingDone>("Task")(
  Struct.omit(Task.fields, "done")
) {}

class TaskPickingIdName extends Schema.Class<TaskPickingIdName>("Task")(
  Struct.pick(Task.fields, "id", "name")
) {}


Any issues/concerns with this approach. Is there a more "Idiomatic" approach to achieving this?
Was this page helpful?