Creating Optional Fields in Effect-TS Schemas

Hi all! Inspired by Drizzle-Zod’s createInsertSchema and createUpdateSchema (where update schemas make fields optional for partial updates), I’d like to create a similar schema variation in Effect-TS with specific fields made optional.
In Zod, I can use refine for custom validation or partial to make fields optional, like this:
const schema = z.object({
  id: z.number(),
  name: z.string(),
  age: z.number(),
}).refine((data) => data.age > 0); // custom validation
const updateSchema = schema.partial({ id: true, name: true }); // id, name optional

With Effect-TS, I have a class-based schema:
export class Chat extends Schema.Class<Chat>("Chat")({
  id: Schema.String,
  name: Schema.String,
  age: Schema.Number,
}) {}


How can I create a version of this schema where id and name are optional, similar to an update schema? Is there a recommended way in Effect-TS to handle this, like Zod’s partial for specific fields?
With helper function

Thanks!
Was this page helpful?