Effect CommunityEC
Effect Community3y ago
8 replies
d10

Understanding Transforms in Zod: Converting from Schema A to Schema B

Coming from using zod, I'm not sure if I'm understanding how to do to transforms properly. If I have 2 schemas like
const schemaA = S.string.pipe(S.length(20));
const schemaB = S.string.pipe(S.length(10));

how do I create a transform to go from A to B? I've read about .transform but not sure how to encode it back for this. If I'm never going to encode can I just do something like
S.transform(
  schemaA,
  schemaB,
  (value) => value.slice(10),
  (_) => _,
);
Was this page helpful?