Effect CommunityEC
Effect Community3y ago
4 replies
Riordan

Limitations of Extending Transformed Struct Schemas

Is there an inherent reason that I cannot extend a transformed struct schema or is it just hard to do? e.g.
const A = Schema.struct({
  a: Schema.literal('a'),
});

const B = Schema.struct({
  b: Schema.literal('b'),
});

const Transform = Schema.transform(
  A,
  B,
  () => ({ b: 'b' as const }),
  () => ({ a: 'a' as const })
);

const Extend = pipe(Transform, Schema.extend(A));
// Error: `extend` can only handle type literals or unions of type literals
const b = Schema.decode(Extend)({ a: 'a' });
Was this page helpful?